#include<bits/stdc++.h>
using namespace std;
int main()
{
int x,c;
cin>>c>>x;
if(x==1||x==3||x==5||x==7||x==8||x==10||x==12)
cout<<31<<endl;
if(x==4||x==6||x==9||x==11)
cout<<30<<endl;
if(x==2)
{
if(c%4==0&&c%100!=0||c%400==0)
cout << 29 << endl;
else
cout << 28 << endl;
}
return 0;
}