{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List

solve :: Int -> Int -> [(Int,Int)] -> Int
solve n c xvs = answer where
  xs = map fst xvs
  vs = map snd xvs
  xsR = map (c -) (reverse xs)
  vsR = reverse vs
  answer = max (solveSub xs vs xsR vsR) (solveSub xsR vsR xs vs)

solveSub :: [Int] -> [Int] -> [Int] -> [Int] -> Int
solveSub xs vs xsR vsR = answer where
  calcG val cost = tail $ scanl' max 0 $
                        zipWith (-) (scanl' (+) 0 val) (0:cost)
  gainA = calcG vs (map (* 2) xs)
  gainB = calcG vsR xsR
  answer = maximum $ zipWith (+) gainA (reverse gainB)

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n,bs_c]:remLines1 = remLines0
      n = readBInt bs_n
      c = readBInt bs_c
      xvs = map (\[x1,x2] -> (readBInt x1,readBInt x2)) remLines1
  in solve n c xvs

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents
