def isLeapYear(year):
    return True if ((year % 400 == 0) or (year % 4 == 0 and year % 100 != 0)) else False

md = [31,28,31,30,31,30,31,31,30,31,30,31]

while True:
    try:
        y, m = map(int, input().split())
        if isLeapYear(y) and m == 2:
            print(29)
        else:
            print(md[m-1])
    except EOFError:
        break