main = do
    let readLine = return . map read . words =<< getLine
    [n_,x_] <- readLine
    as <- readLine
    let reduce [a1,a2]
	  | a1+a2 <= x_	= 0
	  | otherwise	= (a1+a2) - x_
	reduce (a1:a2:as)
	  | a1+a2 <= x_	    = reduce (a2:as)
	  | otherwise	    = let   over = (a1+a2)-x_
				    a2' = maximum [0,a2-over]
		in over + reduce (a2':as)
    print $ reduce as