output_description: Print the minimum number of operations required to achieve the objective.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      N x
      a_1 a_2 ... a_N
attempt: import sys
  import math
  import collections
  import itertools
  import array
  import inspect
  
  # Set max recursion limit
  sys.setrecursionlimit(1000000)
  
  
  # Debug output
  def chkprint(*args):
      names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()}
      print(", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args))
  
  
  # Binary converter
  def to_bin(x):
      return bin(x)[2:]
  
  
  def li_input():
      return [int(_) for _ in input().split()]
  
  
  def gcd(n, m):
      if n % m == 0:
          return m
      else:
          return gcd(m, n % m)
  
  
  def gcd_list(L):
      v = L[0]
  
      for i in range(1, len(L)):
          v = gcd(v, L[i])
  
      return v
  
  
  def lcm(n, m):
      return (n * m) // gcd(n, m)
  
  
  def lcm_list(L):
      v = L[0]
  
      for i in range(1, len(L)):
          v = lcm(v, L[i])
  
      return v
  
  
  # Width First Search (+ Distance)
  def wfs_d(D, N, K):
      """
      D: 隣接行列(距離付き)
      N: ノード数
      K: 始点ノード
      """
  
      dfk = [-1] * (N + 1)
      dfk[K] = 0
  
      cps = [(K, 0)]
      r = [False] * (N + 1)
      r[K] = True
      while len(cps) != 0:
          n_cps = []
          for cp, cd in cps:
              for i, dfcp in enumerate(D[cp]):
                  if dfcp != -1 and not r[i]:
                      dfk[i] = cd + dfcp
                      n_cps.append((i, cd + dfcp))
                      r[i] = True
  
          cps = n_cps[:]
  
      return dfk
  
  
  # Depth First Search (+Distance)
  def dfs_d(v, pre, dist):
      """
      v:  現在のノード
      pre: １つ前のノード
      dist: 現在の距離
  
      以下は別途用意する
      D: 隣接リスト(行列ではない)
      D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
      """
  
      global D
      global D_dfs_d
  
      D_dfs_d[v] = dist
  
      for next_v, d in D[v]:
          if next_v != pre:
              dfs_d(next_v, v, dist + d)
  
      return
  
  
  def sigma(N):
      ans = 0
      for i in range(1, N + 1):
          ans += i
      return ans
  
  
  class Combination:
      def __init__(self, n, mod):
  
          g1 = [1, 1]
          g2 = [1, 1]
          inverse = [0, 1]
          for i in range(2, n + 1):
              g1.append((g1[-1] * i) % mod)
              inverse.append((-inverse[mod % i] * (mod // i)) % mod)
              g2.append((g2[-1] * inverse[-1]) % mod)
          self.MOD = mod
          self.N = n
          self.g1 = g1
          self.g2 = g2
          self.inverse = inverse
  
      def __call__(self, n, r):
          if r < 0 or r > n:
              return 0
          r = min(r, n - r)
          return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD
  
  
  # --------------------------------------------
  
  dp = None
  
  
  def main():
      N, X = li_input()
      A = li_input()
  
      ans = 0
  
      for i in range(len(A)):
          if A[i] > X:
              ans += A[i] - X
              A[i] = X
  
      for i in range(1, len(A) - 1, 2):
          s1 = A[i] + A[i - 1]
          s2 = A[i] + A[i + 1]
  
          if s1 > X or s2 > X:
              s = max(s1, s2)
              d = s - X
              ans += d
              A[i] -= d
  
      print(ans)
  
  
  main()
  
problem_description: Statement
  
  There are N boxes arranged in a row. Initially, the i-th box from the left
  contains a_i candies.
  
  Snuke can perform the following operation any number of times:
  
    * Choose a box containing at least one candy, and eat one of the candies in the chosen box.
  
  His objective is as follows:
  
    * Any two neighboring boxes contain at most x candies in total.
  
  Find the minimum number of operations required to achieve the objective.
samples: [{"input": "3 3\n    2 2 2", "output": "1\n    \n\nEat one candy in the second box. Then, the number of candies in each box\nbecomes (2, 1, 2).\n\n* * *"}, {"input": "6 1\n    1 6 1 2 0 4", "output": "11\n    \n\nFor example, eat six candies in the second box, two in the fourth box, and\nthree in the sixth box. Then, the number of candies in each box becomes (1, 0,\n1, 0, 0, 1).\n\n* * *"}, {"input": "5 9\n    3 1 4 1 5", "output": "0\n    \n\nThe objective is already achieved without performing operations.\n\n* * *"}, {"input": "2 0\n    5 5", "output": "10\n    \n\nAll the candies need to be eaten."}]