import Data.List

primes::[Int]
primes=2:3:p where 
    p=5:q 1 7 p
    q m s (p:ps)=[n|n<-[x+y|x<-[s,s+6..p*p-2],y<-[0,4]],gcd(toInteger n)m<2]++q(m*toInteger p)(p*p)ps

fs ps=unfoldr fp.(,,)0 ps where
    fp (0,_,1)=Nothing
    fp (_,[],n)=Just((n,1),(0,[],1))
    fp (c,a@(p:r),n)|n`mod`p==0=fp(c+1,a,n`div`p)|c==0=fp(0,r,n)|c/=0=Just((p,c),(0,r,n))

main=do
    [n,p]<-map read.words<$>getLine
    print $ product $ map (\(a,b)->a^(b`div`n)) $ fs (takeWhile (<=1000001) primes) p
