N = int(input()) M = int(input()) N %= 10 M %= 4 if M == 0: print(N) else: print(pow(N, M, 10))