#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b;
if(b==2){
   
    if(a%4==0&&a%100!=0||a%400==0)cout<<"29";
else
cout<<"28";}
   
    else if(b==2||b==4||b==6||b==9||b==11)
    cout<<"30";
    else
    cout<<"31";
    return 0;
}
/**************************************************************
	Problem: 2096
	User: wengsihan
	Language: C++
	Result: Accepted
	Time:18 ms
	Memory:2072 kb
****************************************************************/