import Control.Monad solve :: Integral a => a -> a -> a solve n d = lcm n d `div` 2 - 1 main :: IO () main = do [n, d] <- map read . words <$> getLine putStrLn $ show $ solve n d