N = input() M = "0" + input() n = int(N[-1]) if n == 0: print(0) exit() m = int(M[-2:]) print(pow(n, m, 10))