N = input() M = input() n = int(N[-1]) m = int(M[-2:]) % 4 if n == 0: print(0) else: print(pow(n, m, 10))