import Control.Monad

staticSushi xs vs c n = max maxa maxb
    where
        _xs = (reverse . map (c-) $ xs) -- 逆時計回りの距離
        svs = scanl1 (+) vs
        _svs = scanl1 (+) . reverse $ vs
        fa = zipWith (-) svs $ (2*) <$> xs
        fb = zipWith (-) _svs $ (2*) <$> _xs
        _ga = reverse . scanl1 max $ fa
        _gb = reverse . scanl1 max $ fb
        maxa = maximum $ [0] ++
                        [svs !! a - xs !! a | a <- [0..(n-1)]] ++
                        [_ga !! (b+1) + _svs !! b - _xs !! b | b <- [0..(n-2)]]
        maxb = maximum $ [0] ++
                        [_svs !! b - _xs !! b | b <- [0..(n-1)]] ++ 
                        [_gb !! (a+1) + svs !! a - xs !! a | a <- [0..(n-2)]]

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