N,M = input(),input() n = 1 for i in range(0,M): n *= N n %= 10 print n