n=int(input()) m=int(input()) out,t=1,n%10 while m: if m%2:out=out*t%10 t=t*t%10 m//=2 print(out)