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

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



prev = ans1 = 0

for a in src:

    if prev+a > X:

        eat = prev+a - X

        ans1 += eat

        prev = max(0, a-eat)

    else:

        prev = a



prev = ans2 = 0

for a in src[::-1]:

    if prev+a > X:

        eat = prev+a - X

        ans2 += eat

        prev = max(0, a-eat)

    else:

        prev = a



print((min(ans1,ans2)))

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

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



ans = 0

for i in range(1,N):

    if A[i] + A[i-1] <= X: continue

    diff = A[i] + A[i-1] - X

    ans += diff

    if diff < A[i]:

        A[i] -= diff

    else:

        #diff -= A[i]

        A[i] = 0

        #A[i-1] -= diff

print(ans)
N, X = list(map(int, input().split()))
src = list(map(int, input().split()))
prev = ans1 = 0
for a in src:
    if prev + a > X:
        eat = prev + a - X
        ans1 += eat
        prev = max(0, a - eat)
    else:
        prev = a
prev = ans2 = 0
for a in src[::-1]:
    if prev + a > X:
        eat = prev + a - X
        ans2 += eat
        prev = max(0, a - eat)
    else:
        prev = a
print((min(ans1, ans2)))

N, X = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
for i in range(1, N):
    if A[i] + A[i - 1] <= X:
        continue
    diff = A[i] + A[i - 1] - X
    ans += diff
    if diff < A[i]:
        A[i] -= diff
    else:
        # diff -= A[i]
        A[i] = 0
        # A[i-1] -= diff
print(ans)

-src = list(map(int, input().split())) -prev = ans1 = 0 -for a in src: -    if prev + a > X: -        eat = prev + a - X -        ans1 += eat -        prev = max(0, a - eat) +A = list(map(int, input().split())) +ans = 0 +for i in range(1, N): +    if A[i] + A[i - 1] <= X: +        continue +    diff = A[i] + A[i - 1] - X +    ans += diff +    if diff < A[i]: +        A[i] -= diff -        prev = a -prev = ans2 = 0 -for a in src[::-1]: -    if prev + a > X: -        eat = prev + a - X -        ans2 += eat -        prev = max(0, a - eat) -    else: -        prev = a -print((min(ans1, ans2))) +        # diff -= A[i] +        A[i] = 0 +        # A[i-1] -= diff +print(ans)