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