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

getsolve :: [Integer] -> Integer -> Integer
getsolve ls x
    | length ls < 2				= 0
    | fstLs + sndLs > x			= afure + getsolve ((sndLs - afure):(tail (tail ls))) x
    | otherwise					= getsolve (tail ls) x
    where fstLs = head ls
          sndLs = head $ tail ls
          afure = fstLs + sndLs - x



