N,M = input(),input() if M == 0: print 1 else: print ((N % 10)*(N % 10)) % 10