import Control.Monad

main = do
  [n,c] <- fmap (map read . words) getLine
  xs <- replicateM n (fmap ((\(x:v:_)->(x,v)) . map read . words) getLine)
  print (solve c xs)


-- MaxState, CurrentState, CurrentX
type State = (Int, (Int, Int))

solve :: Int -> [(Int,Int)] -> Int
solve c xs =
  solveTurn roundR roundL
  where
    roundR = scanl f (0,(0,0)) xs
    roundL = scanr (flip f) (0,(0,0)) [(c-x,v)|(x,v)<-xs]

    f (m,(s,y)) (x,v) = let s' = s-(x-y)+v in (max m s', (s', x))


solveTurn :: [State] -> [State] -> Int
solveTurn ss1 ss2 =
  maximum (go ss1 (tail ss2) ++ go (reverse ss2) (tail (reverse ss1)))
  where
    go :: [State] -> [State] -> [Int]
    go [(m1,(s1,x1))]     _                  = [m1]
    go ((m1,(s1,x1)):tt1) ((m2,(s2,x2)):tt2) = s1+m2-x1 : go tt1 tt2