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