N, X = list(map(int, input().split()))

A = list(map(int, input().split()))

ans = 0

 

if A[0] > X:

    ans += A[0] - X

    A[0] = X

    

for i in range(N-1):

    if A[i] + A[i+1] > X:

        ans -= X - (A[i] + A[i + 1])

        A[i+1] += X - (A[i] + A[i+1])

 

print(ans)
n,k=list(map(int,input().split()))

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

v=sum(a)

if k<a[0]:

    a[0]=k

for i in range(n-1):

    if k<a[i]+a[i+1]:

        a[i+1]=k-a[i]

print((v-sum(a)))
N, X = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
if A[0] > X:
    ans += A[0] - X
    A[0] = X
for i in range(N - 1):
    if A[i] + A[i + 1] > X:
        ans -= X - (A[i] + A[i + 1])
        A[i + 1] += X - (A[i] + A[i + 1])
print(ans)

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
v = sum(a)
if k < a[0]:
    a[0] = k
for i in range(n - 1):
    if k < a[i] + a[i + 1]:
        a[i + 1] = k - a[i]
print((v - sum(a)))

-N, X = list(map(int, input().split())) -A = list(map(int, input().split())) -ans = 0 -if A[0] > X: -    ans += A[0] - X -    A[0] = X -for i in range(N - 1): -    if A[i] + A[i + 1] > X: -        ans -= X - (A[i] + A[i + 1]) -        A[i + 1] += X - (A[i] + A[i + 1]) -print(ans) +n, k = list(map(int, input().split())) +a = list(map(int, input().split())) +v = sum(a) +if k < a[0]: +    a[0] = k +for i in range(n - 1): +    if k < a[i] + a[i + 1]: +        a[i + 1] = k - a[i] +print((v - sum(a)))