import math N = int(input()) K = int(input()) N %= 6 a = [ [0], [1], [4, 2], [3], [4], [1, 5] ] b = a[N] K %= len(b) print("285714"[(b[K] + 5) % 6])