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

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



ans = 0

for i in range(n-1):

  s = l[i]+l[i+1]

  if s > x:

    if l[i+1] >= (s-x):

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

      ans += (s-x)

    else:

      l[i+1] = 0

      ans += (s-x)

print(ans)

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

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



ans = 0

for i in range(n-1):

    y =  A[i]+A[i+1]

    if y > x:

        r = y-x

        if A[i+1] >= r:

            A[i+1] -= r

            ans += r

        else:

            A[i+1] = 0

            A[i] -= (r-A[i+1])

            ans += r

print(ans)

n, x = list(map(int, input().split()))
l = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
    s = l[i] + l[i + 1]
    if s > x:
        if l[i + 1] >= (s - x):
            l[i + 1] -= s - x
            ans += s - x
        else:
            l[i + 1] = 0
            ans += s - x
print(ans)

n, x = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
    y = A[i] + A[i + 1]
    if y > x:
        r = y - x
        if A[i + 1] >= r:
            A[i + 1] -= r
            ans += r
        else:
            A[i + 1] = 0
            A[i] -= r - A[i + 1]
            ans += r
print(ans)

-l = list(map(int, input().split())) +A = list(map(int, input().split())) -    s = l[i] + l[i + 1] -    if s > x: -        if l[i + 1] >= (s - x): -            l[i + 1] -= s - x -            ans += s - x +    y = A[i] + A[i + 1] +    if y > x: +        r = y - x +        if A[i + 1] >= r: +            A[i + 1] -= r +            ans += r -            l[i + 1] = 0 -            ans += s - x +            A[i + 1] = 0 +            A[i] -= r - A[i + 1] +            ans += r