#include<bits/stdc++.h>
using namespace std;
const int a[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int b[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
if(n % 10 == 0 && n % 100 / 10 == 0 && m == 2)
cout << a[m];
else if(n % 4 == 0 && m == 2)
cout << a[m];
else
cout << b[m];
return 0;
}