import qualified Data.ByteString.Char8 as B
import Data.Maybe

main = do
    [_, x] <- map read . words <$> getLine :: IO [Int]
    as <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]
    print $ f x as

f x (y:y':ys) = let a = if y + y' > x then (y + y') - x else 0
                    b = max 0 (y' - a)
                in a + f x (b:ys)
f x [y] = max 0 $ y - x
f x []  = 0
