g = lambda n: n%4 if n%4!=0 else 4 f = lambda n,m: 1 if m==0 else 0 if n==0 else n**g(m)%10 print(f(int(input()[-1:]), int(input()[-2:])))