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