#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
scanf("%d %d",&a,&b);
if(a%4==0 and a%100!=0 or a%100==0)
{if(b==1 or 3 or 5 or 7 or 8 or 10 or 12)
{printf("31");}
else if(b==4 or 6 or 9 or 11)
{printf("30");}
else(b==2);
{printf("29");}}
else
{if(b==1 or 3 or 5 or 7 or 8 or 10 or 12)
{printf("31");}
else if(b==4 or 6 or 9 or 11)
{printf("30");}
else(b==2);
{printf("28");}}
return 0;
}