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