{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as VU
import Data.Char
import Control.Monad
import Data.Array.Unboxed
import Data.Array
import Data.Array.IO

solve :: IOUArray Int Int -> Int -> Int -> IO Int
solve arr n x
    | n == 2 = do
        a <- readArray arr 0
        b <- readArray arr 1
        return $ max (a+b-x) 0
    | otherwise = do
        res <- forM [0..n-2] $ \i -> do
            if (even i) 
                then adjust arr (i,i+1) x
                else adjust arr (i+1,i) x
        return $ sum res
    where
        adjust :: IOUArray Int Int -> (Int, Int) -> Int -> IO Int
        adjust arr (i,j) x = do
            iv <- readArray arr i
            jv <- readArray arr j
            let diff = max (iv+jv-x) 0
            unless (diff == 0) $ do
                if (jv >= diff)
                    then do
                        writeArray arr j (jv-diff)
                    else do
                        writeArray arr j 0
                        writeArray arr i (iv + (jv-diff))
            return diff

main = do
    [n, x] <- map read . words <$> getLine :: IO [Int]
    as <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    (as' :: IOUArray Int Int) <- thaw $ Data.Array.listArray (0,n-1) $ VU.toList as
    solve as' n x >>= print