N = int(input()) M = int(input()) n = N % 10 A = n for i in range(M-1): A *= n if A >= 10: A %= 10 print(A)