https://www.luogu.com.cn/problem/P5716
"""
P5716 【深基3.例9】月份天数
https://www.luogu.com.cn/problem/P5716
"""
a=[0,31,28,31,30,31,30,31,31,30,31,30,31]
#print(a)
year,month=map(int,input().split())
if (year%4==0) and (year%100!=0):
a[2]=29
else:
if year%400==0:
a[2]=29
print(a[month])