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: def getN():
      return int(input())
  
  
  def getNM():
      return map(int, input().split())
  
  
  def getList():
      return list(map(int, input().split()))
  
  
  def getArray(intn):
      return [int(input()) for i in range(intn)]
  
  
  from collections import defaultdict, deque
  from sys import exit
  import heapq
  import math
  import copy
  from bisect import bisect_left, bisect_right
  
  import sys
  
  sys.setrecursionlimit(1000000000)
  
  N, X = getNM()
  A = getList()
  between = [A[i] + A[i + 1] - X for i in range(N - 1)]
  ans = 0
  flag = True
  while flag:
      flag = False
      for i in range(N - 2):
          if between[i] > 0 and between[i + 1] > 0:
              minuspoint = min(between[i], between[i + 1], A[i + 1])
              A[i + 1] -= minuspoint
              ans += minuspoint
              flag = True
      between = [A[i] + A[i + 1] - X for i in range(N - 1)]
  for i in between:
      if i > 0:
          ans += i
  print(ans)
  
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."}]