main=do
    (n:m:_)<-map read.words<$>getLine::IO[Int]
    print $ sol n m
sol n m = div m $ minimum $ filter (>=n) $ divs m
divs = d 1 where
    d k m
        | k^2>m = []
        | mod m k ==0 = k : div m k : d (k+1) m
        | otherwise   = d (k+1) m