#167 N^Mmod10 N=int(input()) M=int(input()) a=1 while M>=0: N%=10 a*=N a%=10 M-=1 print(a)