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:

        

        if X - a[i] >= 0:

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

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

        else:

            ans += a[i+1]

            a[i+1] = 0

            ans += a[i] - X

            a[i] = X

            

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

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

ans = 0



if a[0] > x:

    ans += a[0] - x

    a[0] = x



for i in range(1, N):

    if a[i] + a[i - 1] > x:

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

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



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:
        if X - a[i] >= 0:
            ans += a[i + 1] - (X - a[i])
            a[i + 1] = X - a[i]
        else:
            ans += a[i + 1]
            a[i + 1] = 0
            ans += a[i] - X
            a[i] = X
print(ans)

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

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