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

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

ans = 0



for i in range(1, n):

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

    tmp = a[i]

    a[i] = max(x-a[i-1], 0)

    ans += tmp - a[i]

  if a[i] == 0 and a[i-1] > x:

    tmp = a[i-1]

    a[i-1] = x

    ans += tmp - a[i-1]

print(ans)






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(1,N):

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

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

        ans += tmp

        A[i] -= tmp



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

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(1, N):
    if A[i] + A[i - 1] > x:
        tmp = A[i] + A[i - 1] - x
        ans += tmp
        A[i] -= tmp
print(ans)

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