N = int(input()) M = int(input()) if M == 0: print(1) else: print(pow(N % 10, M % 4 + 4, 10))