import Control.Monad

staticSushi xs vs c n = max maxa maxb
    where
        xs' = 0 : xs
        _xs' = 0 : (reverse . map (c-) $ xs)
        svas = scanl (+) 0 vs
        svbs = scanl (+) 0 . reverse $ vs
        maxa = maximum [svas !! a + svbs !! b - (xs' !! a * 2 + _xs' !! b) | a <- [0..(n-1)], b <- [0..n-(a+1)]]
        maxb = maximum [svas !! a + svbs !! b - (xs' !! a + _xs' !! b * 2) | b <- [0..(n-1)], a <- [0..n-(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