a = [1, 3, 5, 7, 8, 10, 12] while True: try: y, m = map(int, input().split()) if m in a: d = 31 elif m == 2: if y % 4 != 0: d = 28 else: d = 29 else: d = 30 print(d) except: break