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 int(n)**g(int(m))%10 print(f(input()[-1:], input()[-2:]))