N = int(input()) M = int(input()) num = N % 10 print(poe(num,M,10))