main = do
  (n:x:_) <- getLine >>= return . map read . words :: IO [Int]
  as <- getLine >>= return . map read . words :: IO [Int]

  print $ solve as x

  where
    solve (a:as) x = sum $ zipWith (-) (a:as) (solve' ((if a<x then a else x) : as) x)

    solve' (a:[]) _ = [a]
    solve' (a:b:as) x = if a+b<=x then a : (solve' (b:as) x) else a : (solve' ((x-a):as) x)
