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