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: #
  # Written by NoKnowledgeGG @YlePhan
  # ('ω')
  #
  # import math
  # mod = 10**9+7
  # import itertools
  # import fractions
  # import numpy as np
  # mod = 10**4 + 7
  """def kiri(n,m):
    r_ = n / m
    if (r_ - (n // m)) > 0:
      return (n//m) + 1
    else:
      return (n//m)"""
  
  """ n! mod m 階乗
  mod = 1e9 + 7
  N = 10000000
  fac = [0] * N
  def ini():
    fac[0] = 1 % mod
    for i in range(1,N):
      fac[i] = fac[i-1] * i % mod"""
  
  """mod = 1e9+7
  N = 10000000
  pw = [0] * N
  def ini(c):
    pw[0] = 1 % mod
    for i in range(1,N):
      pw[i] = pw[i-1] * c % mod"""
  
  """
  def YEILD():
    yield 'one'
    yield 'two'
    yield 'three'
  generator = YEILD()
  print(next(generator))
  print(next(generator))
  print(next(generator))
  """
  """def gcd_(a,b):
    if b == 0:#結局はc,0の最大公約数はcなのに
      return a
    return gcd_(a,a % b) # a = p * b + q"""
  """def extgcd(a,b,x,y):
    d = a
    if b!=0:
      d = extgcd(b,a%b,y,x)
      y -= (a//b) * x
      print(x,y)
    else:
      x = 1
      y = 0
    return d"""
  
  
  def readInts():
      return list(map(int, input().split()))
  
  
  def main():
      n, x = readInts()
      A = readInts()
      ans = 0
      i = 0
      if sum(A[i : i + 2]) > x:
          sum_ = sum(A[i : i + 2])
          # preprocessing
  
          if A[i + 1] - (sum_ - x) < 0:
              A[i + 1] = 0
              ans += A[i + 1]
              nya = sum_ - x
              A[i] -= nya
              ans += nya
          else:
              nya = sum_ - x
              A[i + 1] -= nya
              ans += nya
  
      for i in range(1, n - 1):
          if sum(A[i : i + 2]) > x:
              sum_ = sum(A[i : i + 2])
              nya = sum_ - x
              A[i + 1] -= nya
              ans += nya
      print(ans)
  
  
  if __name__ == "__main__":
      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."}]