#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int year,mouth,day;
	cin>>year>>mouth;
	if((year%4==0&&year%100!=0)||year%400==0){//ÈòÄê
		day=29;
	}else{
		day=28;
	}
	switch(mouth){
		case 1:case 3:case 5:case 7:case 8:case 10:case 12:cout<<31;
		break;
		case 2:cout<<day;
		break;
		default:cout<<30;
	}
	return 0;
}
