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