x,n = map(int,input().split()) if (x + n) <= 7: print(x+n) else: if (x + n)%7 == 0: print((x+n)%7+7) else: print((x+n)%7)