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