
import Data.List (last)

enumDivisor x = 1 : f x 2 where
  f 1 _ = []
  f n r
    | r > lim = [n]
    | n`mod`r==0 = r : f n (r+1)
    | otherwise = f n (r+1)
  lim = floor $ (sqrt :: Double -> Double) $ fromIntegral x

solv 1 m = m
solv n m = last . filter (<=(div m n)) $ enumDivisor m

main = do
  [n,m] <- map read . words <$> getLine :: IO [Int]
  print $ solv n m
