import Control.Monad
import Text.Printf
import Control.Applicative
import Data.List as L

getInts :: IO [Integer]
getInts = map read . words <$> getLine

main :: IO()
main = do
  [n, c] <- map read . words <$> getLine
  b <- replicateM n getInts
  printf "%s" $ slv n (fromIntegral c) b

slv :: Int -> Integer -> [[Integer]] -> String
slv n a b | maxVal <= 0 = show 0
          | otherwise = show $ cal - ofVal
  where revLs = reverse $ map (revVal a) b
        route = revLs ++ b
        calc1ret = map calc1 route
        maxVal = maximum calc1ret
        routeValTuple = zip route calc1ret
        startPos = take n $ dropWhile (\x -> snd x < maxVal) routeValTuple
        ofVal = offsetVal (head startPos) (last startPos)
        cal = maximum $ scanl1 (+) (map snd startPos)

calc1 :: [Integer] -> Integer
calc1 [x, v] | x > 0= v - x
             | otherwise = v + x

revVal :: Integer -> [Integer] -> [Integer]
revVal a [x, v] = [x - a, v] 

offsetVal :: ([Integer], Integer) -> ([Integer], Integer) -> Integer
offsetVal x y | head(fst x) > 0 && head(fst y) > 0 = 0
              | head(fst x) < 0 && head(fst y) < 0 = 0
              | otherwise = min (abs(head(fst x))) (abs(head(fst y)))
 
