n, m= int(input()), int(input()) print(pow(n%10,(m%4 if m%4 or not m else 4)))