#include<iostream>
using namespace std;
int leapyear(int);
int d[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
int y,m;
while(cin>>y>>m)
{
d[1]+=leapyear(y);
cout<<d[m-1]<<endl;
}
}
int leapyear(int a)
{
if((a%4==0&&a%100!=0)||a%400==0)
return 1;
else
return 0;
}