import Control.Applicative main :: IO () main = do [n,d] <- (map read . words) <$> getLine :: IO[Int] print $ solve n d solve :: Integral a => a -> a -> a solve x y = (x `div` gcd x y) - 1