import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)



n, x, *a = list(map(int, read().split()))

memo = 0

cnt = 0

if a[0] > x:

    cnt += a[0] - x

    a[0] = x

for i in range(n - 1):

    if a[i + 1] > x:

        cnt += a[i + 1] - x

        a[i + 1] = x

    v = a[i] + a[i + 1] - memo

    if v > x:

        memo = v - x

    else:

        memo = 0

    cnt += memo

print(cnt)

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)



n, x, *a = list(map(int, read().split()))

memo = [0] * n

ans = 0

if a[0] > x:

    ans += a[0] - x

    a[0] = x

for i in range(n - 1):

    memo[i] = a[i] + a[i + 1]

for i, check in enumerate(memo):

    if check > x:

        ans += check - x

        memo[i + 1] -= check - x

print(ans)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
n, x, *a = list(map(int, read().split()))
memo = 0
cnt = 0
if a[0] > x:
    cnt += a[0] - x
    a[0] = x
for i in range(n - 1):
    if a[i + 1] > x:
        cnt += a[i + 1] - x
        a[i + 1] = x
    v = a[i] + a[i + 1] - memo
    if v > x:
        memo = v - x
    else:
        memo = 0
    cnt += memo
print(cnt)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
n, x, *a = list(map(int, read().split()))
memo = [0] * n
ans = 0
if a[0] > x:
    ans += a[0] - x
    a[0] = x
for i in range(n - 1):
    memo[i] = a[i] + a[i + 1]
for i, check in enumerate(memo):
    if check > x:
        ans += check - x
        memo[i + 1] -= check - x
print(ans)

-memo = 0 -cnt = 0 +memo = [0] * n +ans = 0 -    cnt += a[0] - x +    ans += a[0] - x -    if a[i + 1] > x: -        cnt += a[i + 1] - x -        a[i + 1] = x -    v = a[i] + a[i + 1] - memo -    if v > x: -        memo = v - x -    else: -        memo = 0 -    cnt += memo -print(cnt) +    memo[i] = a[i] + a[i + 1] +for i, check in enumerate(memo): +    if check > x: +        ans += check - x +        memo[i + 1] -= check - x +print(ans)