N = int(input()) M = int(input()) n = N % 10 A = n ** M if A >= 10: A %= 10 print(A)