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

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

candy = min(a[0], x)

ans = a[0] - candy

a[0] = candy



for i in range(1, N):

    candy += a[i]

    if candy > x:

        m = candy - x

        ans += m

        a[i] -= m

        candy -= a[i - 1] + m

    else:

        candy -= a[i - 1]



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

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

candy = min(a[0], x)

ans = a[0] - candy

a[0] = candy



for i in range(1, N):

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

    if candy > x:

        m = candy - x

        ans += m

        a[i] -= m



print(ans)
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
candy = min(a[0], x)
ans = a[0] - candy
a[0] = candy
for i in range(1, N):
    candy += a[i]
    if candy > x:
        m = candy - x
        ans += m
        a[i] -= m
        candy -= a[i - 1] + m
    else:
        candy -= a[i - 1]
print(ans)

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
candy = min(a[0], x)
ans = a[0] - candy
a[0] = candy
for i in range(1, N):
    candy = a[i - 1] + a[i]
    if candy > x:
        m = candy - x
        ans += m
        a[i] -= m
print(ans)

-    candy += a[i] +    candy = a[i - 1] + a[i] -        candy -= a[i - 1] + m -    else: -        candy -= a[i - 1]