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

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

acc = 0

ans = 0

for a in A:

    eat = max(acc + a - x, 0)

    ans += eat

    acc = a - eat

acc = 0

ans2 = 0

for a in A:

    eat = max(acc + a - x, 0)

    ans2 += eat

    acc = a - eat

print((min(ans, ans2)))
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:

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

        A[i]-=y

        ans+=y

print(ans)
N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
acc = 0
ans = 0
for a in A:
    eat = max(acc + a - x, 0)
    ans += eat
    acc = a - eat
acc = 0
ans2 = 0
for a in A:
    eat = max(acc + a - x, 0)
    ans2 += eat
    acc = a - eat
print((min(ans, ans2)))

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

-acc = 0 -for a in A: -    eat = max(acc + a - x, 0) -    ans += eat -    acc = a - eat -acc = 0 -ans2 = 0 -for a in A: -    eat = max(acc + a - x, 0) -    ans2 += eat -    acc = a - eat -print((min(ans, ans2))) +if A[0] > x: +    ans += A[0] - x +    A[0] = x +for i in range(1, N): +    if A[i] + A[i - 1] > x: +        y = A[i] + A[i - 1] - x +        A[i] -= y +        ans += y +print(ans)