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