#2022/5/19 14:38
#先判断闰年和平年2月份的区别
while 1:
    try:
        a,b=map(int,input().split())
        if (a%4==0 and a%100!=0 or a%400==0) and b==2:
            print(29)
        elif (a%4!=0 and a%100==0 or a%400!=0) and b==2:
            print(28)
        elif b==1 or b==3 or b==5 or b==7 or b==8 or b==10 or b==12:
            print(31)
        elif b==4 or b==6 or b==9 or b==11:
            print(30)
    except:
        break