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: # @oj: atcoder
  # @id: hitwanyang
  # @email: 296866643@qq.com
  # @date: 2020-08-14 17:33
  # @url:https://atcoder.jp/contests/abc048/tasks/arc064_a
  import sys, os
  from io import BytesIO, IOBase
  import collections, itertools, bisect, heapq, math, string
  from decimal import *
  
  # region fastio
  
  BUFSIZE = 8192
  
  BUFSIZE = 8192
  
  
  class FastIO(IOBase):
      newlines = 0
  
      def __init__(self, file):
          self._fd = file.fileno()
          self.buffer = BytesIO()
          self.writable = "x" in file.mode or "r" not in file.mode
          self.write = self.buffer.write if self.writable else None
  
      def read(self):
          while True:
              b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
              if not b:
                  break
              ptr = self.buffer.tell()
              self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
          self.newlines = 0
          return self.buffer.read()
  
      def readline(self):
          while self.newlines == 0:
              b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
              self.newlines = b.count(b"\n") + (not b)
              ptr = self.buffer.tell()
              self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
          self.newlines -= 1
          return self.buffer.readline()
  
      def flush(self):
          if self.writable:
              os.write(self._fd, self.buffer.getvalue())
              self.buffer.truncate(0), self.buffer.seek(0)
  
  
  class IOWrapper(IOBase):
      def __init__(self, file):
          self.buffer = FastIO(file)
          self.flush = self.buffer.flush
          self.writable = self.buffer.writable
          self.write = lambda s: self.buffer.write(s.encode("ascii"))
          self.read = lambda: self.buffer.read().decode("ascii")
          self.readline = lambda: self.buffer.readline().decode("ascii")
  
  
  sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
  input = lambda: sys.stdin.readline().rstrip("\r\n")
  
  
  # ------------------------------
  def main():
      n, x = map(int, input().split())
      a = list(map(int, input().split()))
      s = a[0]
      ans = 0
      for i in range(1, len(a)):
          if s + a[i] > x:
              temp = s + a[i] - x
              ans += temp
              if temp >= a[i]:
                  # ans+=(temp-a[i])
                  a[i] = 0
              else:
                  a[i] = a[i] - temp
          s = a[i]
      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."}]