#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(a%4000||(a%40&&a%100!=0)){
if(b1||b3||b5||b7||b8||b10||b12){
cout<<"31";
}else if(b4||b6||b9||b11){
cout<<"30";
}else{
cout<<"29";
}
}else{
if(b1||b3||b5||b7||b8||b10||b12){
cout<<"31";
}else if(b4||b6||b9||b11){
cout<<"30";
}else{
cout<<"28";
}
}
}