def inpl(): return input().split()

n, x = list(map(int, inpl()))

a = list(map(int, inpl()))

ans = 0

if a[0] > x:

    ans += a[0] - x

    a[0] = x        

for i in range(1, n):

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

        ans += (a[i-1] + a[i]) - x

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

print(ans)

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

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



ans = 0

b = 0

for i in range(n):

    c = b + a[i]

    if c > x:

        ans += c - x

        b = a[i] + x - c

    else:

        b = a[i]



print(ans)
def inpl():
    return input().split()


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

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

-def inpl(): -    return input().split() - - -n, x = list(map(int, inpl())) -a = list(map(int, inpl())) +n, x = list(map(int, input().split())) +a = list(map(int, input().split())) -if a[0] > x: -    ans += a[0] - x -    a[0] = x -for i in range(1, n): -    if (a[i - 1] + a[i]) > x: -        ans += (a[i - 1] + a[i]) - x -        a[i] = x - a[i - 1] +b = 0 +for i in range(n): +    c = b + a[i] +    if c > x: +        ans += c - x +        b = a[i] + x - c +    else: +        b = a[i]