import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

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

main = do
    [n,x] <- getIntList
    as <- getIntList
    let s = foldl' (solve x) (0,0) as
    print $ fst s

solve x (s, a) b | a+b <= x = (s, b)
                 | otherwise = (s+a+b-x, max (x-a) 0)