import Control.Applicative
import Control.Monad
--import qualified Data.Sequence as Seq
import Data.List

main = do
  [n,c] <- map read . words <$> getLine :: IO [Int]
  xvs <- replicateM n $ readIntPair . words <$> getLine
  print $ solve n c xvs --sortedBy fst  

readIntPair :: [String] -> (Integer,Integer)
readIntPair =  \[a,b]->(read a,read b)

solve :: Int -> Int -> [(Integer,Integer)]-> Integer
solve n c xvs =
  maximum candidate
  where
    n' = fromIntegral n
    c' = fromIntegral c
    xvs_rev = reverse xvs
    xcs_r = scanl (\x y-> (fst y,snd x + snd y)) (0,0) xvs
    xcs_l = scanl (\x y-> (c' - fst y,snd x + snd y)) (0,0) xvs_rev
    choose m =
      let (xr,getcalr) = xcs_r!!m in
      let (xl,getcall) = maximumBy (\a b -> compare (snd a - fst a) (snd b -fst b))
            $ map ((!!) xcs_l) [0..n'-m] in
      getcalr + getcall - ((min xr xl)*2 + (max xr xl))        
    candidate = map choose [0..(div n' 2+(n'`mod`2))]
