

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

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



cdy=0

for i in range(n-1):

    ai=a[i]

    aip=a[i+1]

    if a[i]>x:

        a[i]=x

        cdy=cdy+ai-x

    ai=a[i]

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

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

        cdy=cdy+ai+aip-x



print(cdy)        

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

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

asum=sum(a)



if a[0]>x:

    a[0]=x

    

for i in range(n-1):

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

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

        

asum=asum-sum(a)

print(asum)
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
cdy = 0
for i in range(n - 1):
    ai = a[i]
    aip = a[i + 1]
    if a[i] > x:
        a[i] = x
        cdy = cdy + ai - x
    ai = a[i]
    if a[i] + a[i + 1] > x:
        a[i + 1] = x - a[i]
        cdy = cdy + ai + aip - x
print(cdy)

n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
asum = sum(a)
if a[0] > x:
    a[0] = x
for i in range(n - 1):
    if a[i] + a[i + 1] > x:
        a[i + 1] = x - a[i]
asum = asum - sum(a)
print(asum)

-cdy = 0 +asum = sum(a) +if a[0] > x: +    a[0] = x -    ai = a[i] -    aip = a[i + 1] -    if a[i] > x: -        a[i] = x -        cdy = cdy + ai - x -    ai = a[i] -        cdy = cdy + ai + aip - x -print(cdy) +asum = asum - sum(a) +print(asum)