N, x = list(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 and x < a[i] :

        ans += a[i+1]+a[i]-x

        

        a[i] = a[i]-(x-a[i+1])

        a[i+1] = 0

        

    elif (a[i]+a[i+1]) > x:

        ans += a[i+1]+a[i]-x

        

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

        

print(ans)
N, x = list(map(int, input().split()))

A = [int(i) for i in input().split()]

A.insert(0, 0)

ans = 0



for i in range(N):

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

        ans += abs(A[i+1]-(x-A[i]))

        A[i+1] = x - A[i]

print(ans)
N, x = list(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 and x < a[i]:
        ans += a[i + 1] + a[i] - x
        a[i] = a[i] - (x - a[i + 1])
        a[i + 1] = 0
    elif (a[i] + a[i + 1]) > x:
        ans += a[i + 1] + a[i] - x
        a[i + 1] = x - a[i]
print(ans)

N, x = list(map(int, input().split()))
A = [int(i) for i in input().split()]
A.insert(0, 0)
ans = 0
for i in range(N):
    if A[i] + A[i + 1] > x:
        ans += abs(A[i + 1] - (x - A[i]))
        A[i + 1] = x - A[i]
print(ans)

-a = list(map(int, input().split())) +A = [int(i) for i in input().split()] +A.insert(0, 0) -for i in range(N - 1): -    if (a[i] + a[i + 1]) > x and x < a[i]: -        ans += a[i + 1] + a[i] - x -        a[i] = a[i] - (x - a[i + 1]) -        a[i + 1] = 0 -    elif (a[i] + a[i + 1]) > x: -        ans += a[i + 1] + a[i] - x -        a[i + 1] = x - a[i] +for i in range(N): +    if A[i] + A[i + 1] > x: +        ans += abs(A[i + 1] - (x - A[i])) +        A[i + 1] = x - A[i]