n =int(input()) m =int(input()) n%=10 if m==0:print(1) else: m=m-1 m%=4; m+=1; d=1; for i in range(m): d*=n print(d%10)