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

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

s = sum(arr)

for i in range(1,N):

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

        if arr[i-1] <= x:

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

        else:

            arr[i] = 0

            if x-arr[i-1] > 0:

                arr[i-1] -= x-arr[i-1]

            else:

                arr[i-1] -= arr[i-1]-x

print((s-sum(arr)))
N, x = list(map(int, input().split()))

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

ans = 0

for i in range(N-1):

    if arr[i] + arr[i+1] >= x:

        tmp = arr[i] + arr[i+1] - x

        if arr[i+1] >= tmp:

            arr[i+1] -= tmp

        else:

            arr[i+1] = 0

        ans += tmp

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

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

-s = sum(arr) -for i in range(1, N): -    if arr[i - 1] + arr[i] >= x: -        if arr[i - 1] <= x: -            arr[i] -= (arr[i] + arr[i - 1]) - x +ans = 0 +for i in range(N - 1): +    if arr[i] + arr[i + 1] >= x: +        tmp = arr[i] + arr[i + 1] - x +        if arr[i + 1] >= tmp: +            arr[i + 1] -= tmp -            arr[i] = 0 -            if x - arr[i - 1] > 0: -                arr[i - 1] -= x - arr[i - 1] -            else: -                arr[i - 1] -= arr[i - 1] - x -print((s - sum(arr))) +            arr[i + 1] = 0 +        ans += tmp +print(ans)