while True:
try:
y,m = map(int,input().split())
if m in (1,3,5,7,8,10,12):
print(31)
if m in (4,6,9,11):
print(30)
if m == 2:
if y%100 == 0:
if y%400 == 0:
print(29)
else:
if y%4 ==0:
print(29)
else:
print(28)
except:
break