import sys ''' n = 0 -> ans = (6) n = 1 -> ans = (1) n = 2 -> 2, 4, 2, 4, ... n = 3 -> 3, 3, 3, ... n = 4 -> 4, 4, 4, ... n = 5 -> 5, 1, 5, 1, ... ''' def main(): s = '285714' n = int(input()) k = int(input()) n %= 6 # print('n:', n) if n == 0: print(s[-1]) elif n == 1: print(s[0]) elif n == 2: if k % 2 == 1: print(s[1]) else: print(s[3]) elif n == 3: print(s[2]) elif n == 4: print(s[3]) else: if n % 2 == 0: print(s[4]) else: print(s[0]) if __name__ == '__main__': main()