import Data.List
import Data.Maybe

main = do
  (n:c:_) <- getLine >>= return . map read . words :: IO [Integer]
  dat <- getContents >>= return . map ((\[x,v] -> (x,v)) . map read . words) . lines :: IO [(Integer,Integer)]

  let
    l = scanl (\(x1,v1) (x2,v2) -> (x2, v1+v2)) (0,0) dat
    r = scanl (\(x1,v1) (x2,v2) -> (c-x2, v1+v2)) (0,0) (reverse dat)
    
    f1 = map (\(x,v) -> v - 2*x) l
    g1 = scanl1 max f1
    h1 = map (\(x,v) -> v - x) r

    f2 = map (\(x,v) -> v - 2*x) r
    g2 = scanl1 max f2
    h2 = map (\(x,v) -> v - x) l


  print $ maximum $ zipWith (+) (reverse g1) h1 ++ zipWith (+) (reverse g2) h2
