import Control.Monad as M main :: IO () main = do [n, d] <- map read . words <$> getLine t <- M.replicateM n $ (\[x, y] -> (x, y)) . map read . words <$> getLine print $ solve d t type Pair = (Int, Int) solve :: Int -> [Pair] -> Int solve d ((t, k):h) = uncurry max . foldl step (t, k - d) $ h where step :: Pair -> Pair -> Pair step (accT, accK) (t, k) = (t + max accT (accK - d), k + max accK (accT - d))