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: from fractions import gcd
  
  # from datetime import date, timedelta
  # from heapq import *
  import heapq
  import math
  from collections import defaultdict, Counter, deque
  from bisect import *
  import itertools
  import fractions
  import sys
  
  sys.setrecursionlimit(10**7)
  MOD = 10**9 + 7
  # input = sys.stdin.readline
  
  
  def lcm(a, b):
      return a * b / fractions.gcd(a, b)
  
  
  def make_divisors(n):
      divisors = []
      for i in range(1, int(n**0.5) + 1):
          if n % i == 0:
              divisors.append(i)
              if i != n // i:
                  divisors.append(n // i)
  
      # divisors.sort()
      return divisors
  
  
  def factorize(n):
      fct = []  # prime factor
      b, e = 2, 0  # base, exponent
      while b * b <= n:
          while n % b == 0:
              n = n // b
              e = e + 1
          if e > 0:
              fct.append((b, e))
          b, e = b + 1, 0
      if n > 1:
          fct.append((n, 1))
      return fct
  
  
  def is_prime(n):
      if n == 1:
          return False
  
      for k in range(2, int(math.sqrt(n)) + 1):
          if n % k == 0:
              return False
  
      return True
  
  
  def primes(n):
      is_prime = [True] * (n + 1)
      is_prime[0] = False
      is_prime[1] = False
      for i in range(2, int(n**0.5) + 1):
          if not is_prime[i]:
              continue
          for j in range(i * 2, n + 1, i):
              is_prime[j] = False
      return [i for i in range(n + 1) if is_prime[i]]
  
  
  def modpow(a, n, mod):
      res = 1
      while n > 0:
          if n & 1:
              res = res * a % mod
          a = a * a % mod
          n >>= 1
      return res
  
  
  def modinv(a, mod):
      return modpow(a, mod - 2, mod)
  
  
  def cnk(a, b):
      MOD = 10**9 + 7
      ret = 1
      for i in range(b):
          ret *= a - i
          ret %= MOD
          ret = ret * modinv(i + 1, MOD) % MOD
      return ret
  
  
  def main():
      n, x = map(int, input().split())
      a = list(map(int, input().split()))
  
      ans = 0
      for i in range(n - 1):
          if a[i] + a[i + 1] <= x:
              continue
  
          v = a[i + 1] + a[i] - x
          if a[i + 1] >= v:
              a[i + 1] -= v
              ans += v
          else:
              ans += a[i + 1]
              v -= a[i + 1]
              a[i + 1] = 0
              a[i] -= v
              ans += v
  
      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."}]