solve :: Int -> Int -> Int -> Int
solve n m i
  | i * i > m = 0
  | m `mod` i /= 0 = solve n m (i + 1)
  | otherwise = max (if n * i <= m then i else 0) $ max (if n <= i then m `div` i else 0) $ solve n m (i + 1)

main :: IO ()
main = do
  [n, m] <- (map (\s -> read s :: Int)) . words <$> getLine
  print $ solve n m 1
