N = int(input()) M = int(input()) if M == 0: print(1) exit() N %= 10 M %= 100 M += 100 print(pow(N, M, 10))