month_dict = {
    30: [4, 6, 9, 11],
    31: [1, 3, 5, 7, 8, 10, 12]
}

def leap_year(year: int):
    if year % 100 == 0 and year % 400 == 0:
        return 1
    if year % 100 != 0 and year % 4 == 0:
        return 1
    return 0

while True:
    try:
        year, month = map(int, input().split())
        if month == 2:
            print(29 if leap_year(year) else 28)
        else:
            for key, value in month_dict.items():
                if month in value:
                    print(key)   
    except:
        break