{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BC
import           Data.List             (transpose, zipWith4)
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  [n, c] <- readInts <$> BC.getLine
  xvs <- map readInts . BC.lines <$> BC.getContents
  print $ solve n c xvs

solve :: Int -> Int -> [[Int]] -> Int
solve n c xvs = max (maximum lhs) (maximum rhs)
  where [xs, vs] = transpose xvs
        ys = 0 : xs
        ys' = map (c -) (xs ++ [c])
        ls = scanl (+) 0 vs
        rs = scanr (+) 0 vs
        lfs = zipWith (-) ls ys
        lgs = scanl1 max lfs
        rfs = zipWith (-) rs ys'
        rgs = scanr1 max rfs
        lhs = zipWith4 (\l r xa xb -> l + r - min xa xb) lfs rgs ys ys'
        rhs = zipWith4 (\l r xa xb -> l + r - min xa xb) lgs rfs ys ys'

readInt :: BC.ByteString -> Int
readInt = fst . fromJust . BC.readInt

readInts :: BC.ByteString -> [Int]
readInts = map readInt . BC.words
