import Control.Monad
import Control.Monad.Trans.State.Strict
import Data.Char (isSpace)
import Data.Maybe (fromJust)
import Data.List
import qualified Data.ByteString.Lazy.Char8 as B
--
type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT (B.readInt . B.dropWhile isSpace)

parseInt2 :: Parser (Int,Int)
parseInt2 = liftM2 (,) parseInt parseInt

parse :: Parser (Int,Int, [(Int,Int)])
parse = do
  (n,c)<-liftM2 (,) parseInt parseInt
  xv<-replicateM n parseInt2
  return (n,c,xv)

main=do
  (n,c,xv) <- fromJust.evalStateT parse <$> B.getContents
  --
  let xvc = ((0,0):).map (\(x,v)->(x,v-x)).scanl1 (\(_,va) (x,v)->(x,va+v)) $ xv
  let xvcc = ((0,0):).map (\(x,v)->(c-x,v-(c-x))).scanl1 (\(_,va) (x,v)->(x,va+v)).reverse $ xv
  --
  print.maximum $ f1 n c xvc xvcc

f1 n c xvc xvcc = concatMap(\((ux,uv),(vx,vv))->[uv-ux+vv,vv-vx+uv]) [((ux,uv),(vx,vv))|cn<-[1..n+1], cc<-[1..n+2-cn], (ux,uv)<-take cn xvc, (vx,vv)<-take cc xvcc]
