{-# LANGUAGE BangPatterns #-}

main :: IO ()
main = do
    [_, x] <- map read . words <$> getLine
    as <- map read . words <$> getLine
    print $ solve x as

solve :: Int -> [Int] -> Int
solve x as = go 0 0 as
    where
        go !acc !a0 [] 
            | a0 > x      = acc + a0 - x
            | otherwise   = acc
        go !acc !a0 (a1:as)
            | a0 + a1 > x = go (acc + a0 + a1 - x) (x - a0) as
            | otherwise   = go acc a1 as