import Prelude main :: IO () main = do [l, k] <- map read . words <$> getLine print $ calc l k calc :: Int -> Int -> Int calc l k | l <= k * 2 = 0 | otherwise = k + calc (l - k * 2) k