mod = 10 N = int(input()) M = int(input()) N %= mod M %= mod print(pow(N, M, mod))