#include<stdio.h>
int Check_Runyear(int year)
{
if (year % 400 == 0 || (year % 4 == 0) && (year % 100 != 0))
return 1;
else
return 0;
}
int main()
{
int year = 0, mon = 0, ret = 0;
while (scanf("%d %d", &year, &mon) != EOF)
{
ret = Check_Runyear(year);
if (mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 || mon == 10 || mon == 12)
printf("31\n");
else if (mon == 2)
{
if (!ret)
printf("28\n");
else
printf("29\n");
}
else
printf("30\n");
}
return 0;
}