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

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

solve :: [Int] -> Int
solve [n, m]
    | v == 0 = r
    | otherwise = head $ filter calc [r, (r - 1)..1]
    where
        (r, v) = m `divMod` n 

        calc ans = y == 0 && x > n + 1
            where
                (x, y) = m `divMod` ans

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