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

solve :: Int -> [Int] -> Int
solve _ [_] = 0
solve x (a:b:as) 
  | a+b <= x = 0 + solve x (b:as)
  | otherwise =
      let 
         d = a+b-x
         b' = b-d
       in if b' >= 0
             then d + solve x ((b-d):as)
             else d + (a-b') + solve x (0:as)