# coding: utf-8 # Here your code ! a= int(input()) b=int(input()) if b%10==0: print(a) else: print(a**(b%10)%10)