import Control.Monad

staticSushi xs vs c n = max maxa maxb
    where
        _xs = (reverse . map (c-) $ xs)
        svas = scanl1 (+) vs
        svbs = scanl1 (+) . reverse $ vs
        maxa = maximum $ [0] ++
                        [svas !! a - xs !! a | a <- [0..(n-1)]] ++
                        [svas !! a + svbs !! b - (xs !! a * 2 + _xs !! b) | a <- [0..(n-1)], b <- [0..(n-1)-(a+1)]]
        maxb = maximum $ [0] ++
                        [svbs !! b - _xs !! b | b <- [0..(n-1)]] ++
                        [svas !! a + svbs !! b - (xs !! a + _xs !! b * 2) | b <- [0..(n-1)], a <- [0..(n-1)-(b+1)]]

main :: IO ()
main = do
    [n,c] <- map read . words <$> getLine
    xvs <- replicateM n (map (read :: String -> Int). words <$> getLine)
    let (xs, vs) = foldr (\[x,y] (accx, accy) -> (x:accx,y:accy)) ([],[]) xvs
    putStrLn $ show $ staticSushi xs vs c n