#include<stdio.h>
int my_runnian(int a)
{
if((a%400==0)||(a%100!=0&&a%4==0))//判断闰年
{
return 1;
}
else
{
return 2;
}
}
void test(int a,int b)
{
int arr[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int brr[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(my_runnian(a)==1)
{
printf("%d\n",arr[b]);
}
else
{
printf("%d\n",brr[b]);
}
}
int main()
{
int year=0;
int moth=0;
while(scanf("%d%d",&year,&moth)!=EOF)
{
test(year,moth);
}
return 0;
}