#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    cin>>x>>y;
    int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
    if((x%4==0 && x%100!=0) || (x%400==0)){
            days[1]=29;
        }
    cout<<days[y-1]<<endl;
}
/**************************************************************
	Problem: 2096
	User: HUANGYIBO
	Language: C++
	Result: Accepted
	Time:14 ms
	Memory:2072 kb
****************************************************************/