#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,c;
cin>>a>>c;
if(c1 or c3 or c5 or c7 or c8 or c10 or c12)
{
cout<<"31";
}
else if(c2)
{
if(a%40 and a%100!=0 or a%4000)
{
cout<<"29";
}
else
{
cout<<"28";
}
}
else cout<<"30";
return 0;
}