import Debug.Trace

main = do
    [n,p] <- map read . words <$> getLine :: IO [Int]
    let candMax = (getMaxCand p n 0) - 1
    print $ candMax
    print $ solve p n candMax

getMaxCand :: Int -> Int -> Int -> Int
getMaxCand val n i = if val >= i^n then getMaxCand val n (i+1) else i 

solve :: Int -> Int -> Int -> Int
solve p n i 
    | i == 1 = 1 
    | amari == 0 = i
    | otherwise = solve p n (i-1)
    where 
        temp = i^n
        amari = p `mod` temp