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