import           Control.Monad
import qualified Data.ByteString.Char8       as BS
import           Data.Maybe
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [n, x] <- getIntList
  ts <- getIntList

  ct <- VM.new 1
  VM.set ct (0::Int)

  as <- VM.new (n+1)
  VM.write as 0 (0::Int)
  forM_ (zip [1..] ts) $ \(i, a) -> VM.write as i a

  forM_ [1..n] $ \i -> do
    ai_1 <- VM.read as (i-1)
    ai <- VM.read as i
    m <- VM.read ct 0
    let d = max (ai_1 + ai - x) 0
    VM.write as i (ai - d)
    VM.write ct 0 (m + d)

  ans <- VM.read ct 0
  print ans