mod=129402307 n=input() m=input() n%=mod ans=1 for d in format(m,'b')[::-1]: if (d=='1')==1: ans=(ans*n)%mod n=(n*n)%mod print ans