import Control.Monad (replicateM)
import Data.List (transpose, inits, sortOn)

main :: IO ()
main = do
  [n, c] <- map read . words <$> getLine :: IO [Int]
  xv <- replicateM n (map read . words <$> getLine) :: IO [[Int]]
  let [xs, vs] = transpose xv
      as' = scanl (\(v1,_x1) (v2,x2) -> (v1 + v2, x2)) (0, 0) $ zip vs xs
      bs' = scanr (\(v1,x1) (v2,_x2) -> (v1 + v2, x1)) (0, 0) $ zip vs (map (c-) xs ++ [0])
      as'' = scanl1 (\(v1,x1) (v2,x2) -> if v1-x1 >= v2-x2 then (v1,x1) else (v2,x2)) as'
      bs'' = scanr1 (\(v1,x1) (v2,x2) -> if v1-x1 >= v2-x2 then (v1,x1) else (v2,x2)) bs'
      cs'' = zipWith (\(v1,x1) (v2,x2) -> v1 - x1 + v2 - x2 - min x1 x2) as'' bs''
  print $ maximum cs''
