s = "428571" n = int(input()) k = int(input()) ans = n % 6 if k % 2 == 0: if ans == 2: ans = 4 elif ans == 5: ans = 1 print(s[ans])