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

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

A2=A[::-1]



ANS=0

for i in range(1,N):

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

        ANS+=(A[i]+A[i-1]-x)

        if A[i]>=A[i]+A[i-1]-x:

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

        else:

            A[i]=0







ANS2=0

for i in range(1,N):

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

        ANS2+=(A2[i]+A2[i-1]-x)

        if A2[i]>=A2[i]+A2[i-1]-x:

            A2[i]-=(A2[i]+A2[i-1]-x)

        else:

            A2[i]=0



print((min(ANS,ANS2)))
N,x=list(map(int,input().split()))

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



ANS=0

for i in range(1,N):

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

        ANS+=(A[i]+A[i-1]-x)

        if A[i]>=A[i]+A[i-1]-x:

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

        else:

            A[i]=0



print(ANS)

N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
A2 = A[::-1]
ANS = 0
for i in range(1, N):
    if A[i] + A[i - 1] > x:
        ANS += A[i] + A[i - 1] - x
        if A[i] >= A[i] + A[i - 1] - x:
            A[i] -= A[i] + A[i - 1] - x
        else:
            A[i] = 0
ANS2 = 0
for i in range(1, N):
    if A2[i] + A2[i - 1] > x:
        ANS2 += A2[i] + A2[i - 1] - x
        if A2[i] >= A2[i] + A2[i - 1] - x:
            A2[i] -= A2[i] + A2[i - 1] - x
        else:
            A2[i] = 0
print((min(ANS, ANS2)))

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

-A2 = A[::-1] -ANS2 = 0 -for i in range(1, N): -    if A2[i] + A2[i - 1] > x: -        ANS2 += A2[i] + A2[i - 1] - x -        if A2[i] >= A2[i] + A2[i - 1] - x: -            A2[i] -= A2[i] + A2[i - 1] - x -        else: -            A2[i] = 0 -print((min(ANS, ANS2))) +print(ANS)