n = input() m = input() n1 = int(n[-1]) m1 = int(m[-2:]) if m1 == 0: print(1) quit() if n1 == 0: print(0) quit() print(pow(n1, m1, 10))