
solv n m = head . filter (\x -> mod m x == 0) $ [bound, bound-1..1]
  where bound = min (div m n) (floor.(sqrt::Double->Double).fromIntegral $ m)

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