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:

    cnt = (A[i]+A[i+1]) - x

    ans += cnt

    A[i+1] -= cnt

    if A[i+1] < 0:

      A[i+1] = 0

      

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

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

ans = 0

limit = x

for a in A:

  if limit < a:

    ans += a - limit

    limit = x - limit

  else:

    limit = x - a

    

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

N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
limit = x
for a in A:
    if limit < a:
        ans += a - limit
        limit = x - limit
    else:
        limit = x - a
print(ans)

-for i in range(N - 1): -    if (A[i] + A[i + 1]) > x: -        cnt = (A[i] + A[i + 1]) - x -        ans += cnt -        A[i + 1] -= cnt -        if A[i + 1] < 0: -            A[i + 1] = 0 +limit = x +for a in A: +    if limit < a: +        ans += a - limit +        limit = x - limit +    else: +        limit = x - a