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.
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, floor
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, x = MAP()
A = LIST()

# Who are you?


#B = [0] * (N - 1)
B = []
for i in range(N-1):
    B.append(A[i+1] + A[i])

B.append(0)

pre = sum(A)
for i in range(N - 1):
    if B[i] > x:
        if A[i+1] >= B[i] - x:
            A[i+1] -= B[i] - x
            B[i+1] -= B[i] - x
            B[i] = x
        else:
            A[i] -= B[i] - x - A[i+1]
            B[i+1] -= B[i] - x
            B[i] = x
            A[i+1] = 0
        #print("A:", A)
        
            #B[i+1] -= B[i] - x
after = sum(A)
print(pre-after)
#print(A)


import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, X = MAP()
A = LIST()

ans = 0
tmp = sum(A)
for i in range(N-1):
    
    a = max(A[i] + A[i+1] - X, 0)

    A[i+1] = max(0, A[i+1]-a)
    
    b = max(0, a - A[i+1])
# print(A)
# print(ans)
c = 0
if A[0] + A[1] > X:
    c = A[0] + A[1] - X
A[0] = A[0] - c
print(tmp-sum(A))