import Control.Applicative main :: IO() main = do [n,d] <- map (read::String->Integer) . words <$> getLine print $ lcm n d `div` d - 1