a=int(input())
b=int(input())
if b==2:
    if a%4==0 and a%100!=0 or a%400==0:
        print(29)
    else:
        print(28)
elif b==1 or 3 or 5 or 7 or 8 or 10 or 12:
    print(31)
else:
    print(30)