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.
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(n-1):
  a1 = a[i]
  a2 = a[i+1]
  a[i+1] -= max(a[i+1],x)
  if a[i+1] < 0:
    a[i] += a[i+1]
    a[i+1] = 0
  ans = a1-a[i]+a2-a[i+1]
print(ans)
    
    
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 13 14:21:46 2018
ABC048C
@author: maezawa
"""

n, x = list(map(int, input().split()))
a = list(map(int, input().split()))

cnt = 0
pre = 0
for i in a:
    if pre + i <= x:
        pre = i
        continue
    elif x-pre >= 0:
        cnt += i - (x-pre)
        pre = x-pre
    else:
        cnt += pre + i - x
        pre = 0

print(cnt)