# coding: utf-8

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

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

S = sum(A)

for i in range(n-1):

    s = A[i+1] + A[i]

    if s > x:

        if s-x > A[i+1]:#後ろから全部引ける時

            t = s-x-A[i+1]

            A[i+1] = 0

            A[i] -= t

        else:#後ろから全部引くと負になるとき(前からも引く)

            A[i+1] -= s - x

print((S - sum(A)))
# coding: utf-8

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

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

S = sum(A)

for i in range(n-1):

    s = A[i+1] + A[i]

    if s > x:

        if A[i+1] >= s-x:

            A[i+1] -= (s-x)

        else:

            t = s-x-A[i+1]

            A[i+1] = 0

            A[i] -= t

print((S - sum(A)))
# coding: utf-8
n, x = list(map(int, input().split()))
A = list(map(int, input().split()))
S = sum(A)
for i in range(n - 1):
    s = A[i + 1] + A[i]
    if s > x:
        if s - x > A[i + 1]:  # 後ろから全部引ける時
            t = s - x - A[i + 1]
            A[i + 1] = 0
            A[i] -= t
        else:  # 後ろから全部引くと負になるとき(前からも引く)
            A[i + 1] -= s - x
print((S - sum(A)))

# coding: utf-8
n, x = list(map(int, input().split()))
A = list(map(int, input().split()))
S = sum(A)
for i in range(n - 1):
    s = A[i + 1] + A[i]
    if s > x:
        if A[i + 1] >= s - x:
            A[i + 1] -= s - x
        else:
            t = s - x - A[i + 1]
            A[i + 1] = 0
            A[i] -= t
print((S - sum(A)))

-        if s - x > A[i + 1]:  # 後ろから全部引ける時 +        if A[i + 1] >= s - x: +            A[i + 1] -= s - x +        else: -        else:  # 後ろから全部引くと負になるとき(前からも引く) -            A[i + 1] -= s - x