N = int(input()[-1]) M = (int(input()[-2:])-1) % 100 + 1 print(pow(N,M,10))