#! /usr/bin/env python3



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

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

cnt = 0

for i in range(N-1):

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

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

        cnt += a

        C[i] = min(C[i+1]-a, 0)

        C[i+1] = max(C[i+1]-a, 0)

print(cnt)
#! /usr/bin/env python3



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

cnt = 0

a = list(map(int, input().split())) + [0]

for i in range(N):

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

        o = a[i] + a[i+1] - M

        cnt += o

        if o > a[i+1]:

            o -= a[i+1]

            a[i+1] = 0

            # a[i] -= o

        else:

            a[i+1] -= o

print(cnt)
#! /usr/bin/env python3
N, x = list(map(int, input().split()))
C = list(map(int, input().split()))
cnt = 0
for i in range(N - 1):
    if C[i] + C[i + 1] > x:
        a = C[i] + C[i + 1] - x
        cnt += a
        C[i] = min(C[i + 1] - a, 0)
        C[i + 1] = max(C[i + 1] - a, 0)
print(cnt)

#! /usr/bin/env python3
N, M = list(map(int, input().split()))
cnt = 0
a = list(map(int, input().split())) + [0]
for i in range(N):
    if a[i] + a[i + 1] > M:
        o = a[i] + a[i + 1] - M
        cnt += o
        if o > a[i + 1]:
            o -= a[i + 1]
            a[i + 1] = 0
            # a[i] -= o
        else:
            a[i + 1] -= o
print(cnt)

-N, x = list(map(int, input().split())) -C = list(map(int, input().split())) +N, M = list(map(int, input().split())) -for i in range(N - 1): -    if C[i] + C[i + 1] > x: -        a = C[i] + C[i + 1] - x -        cnt += a -        C[i] = min(C[i + 1] - a, 0) -        C[i + 1] = max(C[i + 1] - a, 0) +a = list(map(int, input().split())) + [0] +for i in range(N): +    if a[i] + a[i + 1] > M: +        o = a[i] + a[i + 1] - M +        cnt += o +        if o > a[i + 1]: +            o -= a[i + 1] +            a[i + 1] = 0 +            # a[i] -= o +        else: +            a[i + 1] -= o