{-# LANGUAGE ScopedTypeVariables #-}
import Data.Array
import Data.Array.Unboxed
import Data.Array.IO
import Control.Monad
import Data.Char

solve :: IOUArray Int Int -> Int -> Int -> IO Int
solve as n x = do
    res <- forM [1..n-1] $ \i -> do
        r <- readArray as i
        s <- readArray as (i-1)
        let diff = r + s - x
        if (diff > 0)
            then do
                if (odd i)
                    then do
                        let diff' = r - diff
                        if diff' >= 0
                            then do
                                writeArray as i diff'
                            else do
                                writeArray as i 0
                                writeArray as (i-1) (s + diff')
                    else do
                        let diff' = s - diff
                        if diff' >= 0
                            then do
                                writeArray as (i-1) diff'
                            else do
                                writeArray as (i-1) 0
                                writeArray as i (r + diff')
                return diff
            else
                return 0
    return $ sum res

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