N,M = input(),input() ans = 1 for i in xrange(M): ans *= N print (ans % 10)