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