main = do str <- getLine let [n, d] = map read (words str) print $ (lcm n d) `div` d - 1