#include<bits/stdc++.h>
using namespace std;
int main(){
int n,s,y;
cin>>n>>y;
s=(n%4==0 && n%100!=0 || n%400==0)?1:0;
if(s==1 && y==2){
cout<<"29";
}else if(y==1 || y==3 || y==5 || y==7 || y==8 || y==10 || y==12){
cout<<"31";
}else{
cout<<"30";
}
return 0;
}