import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main=do
    [n,x]<-map read.words<$>getLine
    as <- unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
    print $ f x 0 as

f x i [a,b] = max 0 (i+(a+b)-x)
f x i (a:b:as)
    | a+b <= x = f x i (b:as)
    | a > x    = f x (i+a-x+b) (0:as)
    | True     = f x (i+a+b-x) ((x-a):as)
