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

main :: IO ()
main = readContents 2 >>= print . solve

solve :: [[Int]] -> Int
solve [[n, x], as] = check 0 as
    where
        check acc (a : b : cs)
            | s <= x = check acc $ b : cs
            | s - x <= b = check (acc + s - x) $ b - s + x : cs
            | otherwise = check (acc + s - x) $ 0 : cs
            where
                s = a + b
        check acc _ = acc 

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine