import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C
import Data.Vector.Unboxed (Vector, (!))
import qualified Data.Vector.Unboxed as U
import Data.Vector.Unboxed.Mutable (unsafeRead, unsafeWrite)
import qualified Data.Vector.Unboxed.Mutable as UM
import Control.Monad.ST
import Data.STRef

main :: IO ()
main = do
  [n, x] <- readInts
  input <- U.fromList <$> readInts
  print $ solve input x

solve :: Vector Int -> Int -> Int
solve input x = U.last $ U.create $ do
  v <- U.thaw input
  vx <- UM.unsafeGrow v 1
  updateCount vx 0
  forM_ [0 .. (UM.length v - 2)] (\i -> do
    a1 <- unsafeRead vx i
    a2 <- unsafeRead vx (i + 1)
    count <- unsafeRead vx lindex
    let sa = a1 + a2
    let dsax = sa - x
    let da2dsax = a2 - dsax
    if dsax > 0
      then do
        updateCount vx (count + dsax)
        if da2dsax >= 0
          then unsafeWrite vx (i + 1) da2dsax
          else unsafeWrite vx i (a1 + da2dsax) >> unsafeWrite vx (i + 1) 0
      else return ()
    )
  return vx
  where
    lindex = U.length input
    updateCount v count = unsafeWrite v lindex count

vectest :: Vector Int -> Vector Int
vectest input = U.create $ do
  v <- UM.replicate 1000 0
  forM_ [0 .. 999] (\i -> do
    let e = input ! i
    unsafeWrite v i e
    )
  return v

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

toTup2 :: [[a]] -> [(a, a)]
toTup2 = map (\ys -> case ys of y : z : zs -> (y, z))

encIdx2 :: Int -> (Int, Int) -> Int
encIdx2 mx (y, x) = y * mx + x

decIdx2 :: Int -> Int -> (Int, Int)
decIdx2 mx idx = (idx `div` mx, idx `mod` mx)

encIdx3 :: (Int, Int) -> (Int, Int, Int) -> Int
encIdx3 (my, mx) (z, y, x) = z * my * mx + y * mx + x

decIdx3 :: (Int, Int) -> Int -> (Int, Int, Int)
decIdx3 (my, mx) idx = (z, y, x)
  where
    basez = my * mx
    z = idx `div` basez
    y = (idx `mod` basez) `div` mx
    x = idx `mod` mx
