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