while 1:
    try:
        y,m = map(int, input().split())
        list = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] 
        day = list[m]
        if y % 400 == 0 or (y % 4 == 0 and y % 100 != 0):
            if m == 2:
                day += 1
        print(day)
    except:
        break