import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLine >>= print . solve 

solve :: [Int] -> Int 
solve [n, p]
    | n == 1 || p == 1 = p
    | otherwise = pf 1 [2..] n p
    
pf :: Int -> [Int] -> Int -> Int -> Int
pf acc (x : xs) n p
    | p == 1 = acc
    | y == 0 = pf acc xs n q
    | otherwise = pf (acc * (x ^ y)) xs n q
    where
        y = z `div` n
        (q, z) = count p x

count :: Int -> Int -> (Int, Int)
count v x = loop 0 m
    where
        m = truncate . succ . logBase (fromIntegral x) $ fromIntegral v
        loop b t
            | t - b < 2 = (v `div` bv, b)
            | v `mod` hv == 0 = loop h t
            | otherwise = loop b h
            where
                h = (b + t) `div` 2
                bv = x ^ b
                hv = x ^ h

readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine