include<stdio.h>
int main()
{
int a, b, c;
while (~scanf("%d%d", &a, &b))
{
if (a % 100 == 0 || a % 4 == 0)
{
if (a % 400 == 0)
{
if (b == 2)
{
printf("29\n");
}
else if (b == 4 || b == 6 || b == 9 || b == 11 )
printf("30\n");
else if (b == 2)
printf("28\n");
else
printf("31\n");
}
else
{
if (b == 2)
{
printf("29\n");
}
else if (b == 4 || b == 6 || b == 9 || b == 11 )
printf("30\n");
else if(b==2)
printf("28\n");
else
printf("31\n");
}
}
else {
if (b == 4 || b == 6 || b == 9 || b == 11 )
printf("30\n");
else if (b == 2)
printf("28\n");
else
printf("31\n");
}
}return 0;
}