from calendar import monthrange a,b = [int(x) for x in input().split()] m=((a-1)%12)+1 d=monthrange(2020,m)[1] print(m+(b%d))