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

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



count = 0

for i in range(N-1):

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

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

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

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

        else:

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

            a[i+1] = 0

            a[i] = x



print (count)

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

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



ans = 0

for i in range(1, N):

    a = A[i - 1]

    b = A[i]

    if a + b <= x:

        continue

    over = (a + b) - x

    ans += over

    A[i] = max(0, b - over)



print (ans)



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

N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
for i in range(1, N):
    a = A[i - 1]
    b = A[i]
    if a + b <= x:
        continue
    over = (a + b) - x
    ans += over
    A[i] = max(0, b - over)
print(ans)

-a = list(map(int, input().split())) -count = 0 -for i in range(N - 1): -    if a[i] + a[i + 1] > x: -        if a[i + 1] >= a[i] + a[i + 1] - x: -            count += a[i] + a[i + 1] - x -            a[i + 1] -= a[i] + a[i + 1] - x -        else: -            count += a[i] + a[i + 1] - x -            a[i + 1] = 0 -            a[i] = x -print(count) +A = list(map(int, input().split())) +ans = 0 +for i in range(1, N): +    a = A[i - 1] +    b = A[i] +    if a + b <= x: +        continue +    over = (a + b) - x +    ans += over +    A[i] = max(0, b - over) +print(ans)