N = int(input()[-1]) M = input() if M == '0': print(1) quit() M = int(M[-2:]) % 4 + 4 print(N**M % 10)