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

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



ans = 0

for i in range(1, N):

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



    # Kより少ないならそのまま

    if candy < K:

        continue



    # 右にあるやつをたべる

    r = min(A[i], candy - K)

    candy -= r

    A[i] -= r

    ans += r

    if candy < K:

        continue



    # 左にあるやつを食べる

    l = min(A[i - 1], candy - K)

    candy -= l

    A[i - 1] -= l

    ans += l

    if candy < K:

        continue



print(ans)

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

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



ans = 0

for i in range(N - 1):

    L = A[i]

    R = A[i + 1]

    eat = max(0, L + R - x)

    ans += eat

    A[i + 1] = max(0, R - eat)



print(ans)
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
for i in range(1, N):
    candy = A[i] + A[i - 1]
    # Kより少ないならそのまま
    if candy < K:
        continue
    # 右にあるやつをたべる
    r = min(A[i], candy - K)
    candy -= r
    A[i] -= r
    ans += r
    if candy < K:
        continue
    # 左にあるやつを食べる
    l = min(A[i - 1], candy - K)
    candy -= l
    A[i - 1] -= l
    ans += l
    if candy < K:
        continue
print(ans)

N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
    L = A[i]
    R = A[i + 1]
    eat = max(0, L + R - x)
    ans += eat
    A[i + 1] = max(0, R - eat)
print(ans)

-N, K = list(map(int, input().split())) +N, x = list(map(int, input().split())) -for i in range(1, N): -    candy = A[i] + A[i - 1] -    # Kより少ないならそのまま -    if candy < K: -        continue -    # 右にあるやつをたべる -    r = min(A[i], candy - K) -    candy -= r -    A[i] -= r -    ans += r -    if candy < K: -        continue -    # 左にあるやつを食べる -    l = min(A[i - 1], candy - K) -    candy -= l -    A[i - 1] -= l -    ans += l -    if candy < K: -        continue +for i in range(N - 1): +    L = A[i] +    R = A[i + 1] +    eat = max(0, L + R - x) +    ans += eat +    A[i + 1] = max(0, R - eat)