main = do [n,d] <- map read . words <$> getLine :: IO [Int] ([t,k]:tks) <- map (map read . words) . lines <$> getContents print (tt d tks t (k-d)) tt _ [] at ak = max at ak tt d ([t,k]:tks) at ak = tt d tks (max (at+t) (ak + (max t k) - d)) (max (ak+k) (at + (max t k) - d))