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

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



res = float('inf')

for b in (a,a[::-1]):

    tmp = 0

    for i in range(n-1):

        if b[i]+b[i+1]>x:

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

            if b[i]>x:

                b[i],b[i+1] = x,0

            else:

                b[i+1] = x - b[i]

    res = min(res,tmp)



print(res)

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

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



res = 0

if a[0]>x:

    res += a[0] - x

    a[0] = x

if a[-1]>x:

    res += a[-1] - x

    a[-1] = x

for i in range(n-1):

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

        res += a[i] + a[i+1] - x

        a[i+1] -= a[i] + a[i+1] - x

print(res)

n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
res = float("inf")
for b in (a, a[::-1]):
    tmp = 0
    for i in range(n - 1):
        if b[i] + b[i + 1] > x:
            tmp += b[i] + b[i + 1] - x
            if b[i] > x:
                b[i], b[i + 1] = x, 0
            else:
                b[i + 1] = x - b[i]
    res = min(res, tmp)
print(res)

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

-res = float("inf") -for b in (a, a[::-1]): -    tmp = 0 -    for i in range(n - 1): -        if b[i] + b[i + 1] > x: -            tmp += b[i] + b[i + 1] - x -            if b[i] > x: -                b[i], b[i + 1] = x, 0 -            else: -                b[i + 1] = x - b[i] -    res = min(res, tmp) +res = 0 +if a[0] > x: +    res += a[0] - x +    a[0] = x +if a[-1] > x: +    res += a[-1] - x +    a[-1] = x +for i in range(n - 1): +    if a[i] + a[i + 1] > x: +        res += a[i] + a[i + 1] - x +        a[i + 1] -= a[i] + a[i + 1] - x