n=int(input()) m=int(input()) n%=10 a=1 for i in range(m): a=(a*n)%10 print(a)