import sys

input = sys.stdin.readline

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

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

res = 0

for i in range(1, N):

  if a[i - 1] + a[i] > x:

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

    res += t

    if t > a[i]:

      t -= a[i]

      a[i] = 0

      a[i - 1] -= t

    else:

      a[i] -= t

print(res)
import sys

input = sys.stdin.readline

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

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

res = 0

for i in range(N - 1):

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

    if a[i] <= X:

      res += a[i] + a[i + 1] - X

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

    else:

      res += a[i] + a[i + 1] - X

      a[i + 1] = 0

print(res)
import sys

input = sys.stdin.readline
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
res = 0
for i in range(1, N):
    if a[i - 1] + a[i] > x:
        t = a[i - 1] + a[i] - x
        res += t
        if t > a[i]:
            t -= a[i]
            a[i] = 0
            a[i - 1] -= t
        else:
            a[i] -= t
print(res)

import sys

input = sys.stdin.readline
N, X = list(map(int, input().split()))
a = list(map(int, input().split()))
res = 0
for i in range(N - 1):
    if a[i] + a[i + 1] > X:
        if a[i] <= X:
            res += a[i] + a[i + 1] - X
            a[i + 1] -= a[i] + a[i + 1] - X
        else:
            res += a[i] + a[i + 1] - X
            a[i + 1] = 0
print(res)

-N, x = list(map(int, input().split())) +N, X = list(map(int, input().split())) -for i in range(1, N): -    if a[i - 1] + a[i] > x: -        t = a[i - 1] + a[i] - x -        res += t -        if t > a[i]: -            t -= a[i] -            a[i] = 0 -            a[i - 1] -= t +for i in range(N - 1): +    if a[i] + a[i + 1] > X: +        if a[i] <= X: +            res += a[i] + a[i + 1] - X +            a[i + 1] -= a[i] + a[i + 1] - X -            a[i] -= t +            res += a[i] + a[i + 1] - X +            a[i + 1] = 0