import Control.Applicative
import Control.Monad
import Data.List

f :: Int -> [Int] -> Int
f x ys = iter 0 ys
  where
    iter n [a]      = n
    iter n (a:b:as)
        | a + b <= x = iter n (b:as)
        | otherwise  = let k = n + ad + bd
                        in k `seq` iter k ((b - bd) : as)
      where
        ov = a + b - x
        bd = min b ov
        ad = min a (ov - bd)

main :: IO ()
main = do
    [_, x] <- fmap read . words <$> getLine :: IO [Int]
    as <- fmap read . words <$> getLine :: IO [Int]
    let ans = f x as
    print ans
