#include<bits/stdc++.h>
using namespace std;
int n,x,a[10001];
bool y(int x){
if (x%4==0&&x%100!=0||x%400==0) return 1;
else return 0;
}
int main() {
cin>>n>>x;
for(int i=1;i<=12;i++){
if(i==2){
if(y(n)) a[i]=29;
else a[i]=28;
}
else if(i==8) a[i]=31;
else if(i%2==1) a[i]=31;
else a[i]=30;
}
cout<<a[x];
return 0;
}