N = int(input()) K = int(input()) a = '285714' ll = [[5,5],[0,0],[1,3],[2,2],[3,3],[4,0]] print(a[ll[N%6][(K-1)%2]])