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