import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.List
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

divisors x = divs' x 1 []
  where divs' x i ds | i*i > x        = sort ds
                     | x `mod` i == 0 = divs' x (i+1) (i:(x`div`i):ds)
                     | otherwise      = divs' x (i+1) ds

main = do
    [n, m] <- getIntList
    let ds = divisors m
        ans = head $ dropWhile (> m `div` n) $ reverse ds
    print ans