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