N,K = map(int, input().split()) N=N%6 if N==0: print(4) elif N==1: print(2) elif N==2: if K%2==1: print(8) else: print(7) elif N==3: print(5) elif N==4: if K%2==1: print(7) else: print(8) elif N==5: if K%2==1: print(1) else: print(2)