n,x=[int(i) for i in input().split()]

a=[int(i) for i in input().split()]



count=0

if(a[0]>x):

    count=a[0]-x

    a[0]=x

    

for ind,i in enumerate(a):

    if(ind==len(a)-1):

      break

    s=i+a[ind+1]

    if(s>x):

        count+=s-x

        a[ind+1]-=s-x

        #s=i+a[ind+1]

print(count)

    

n,x=[int(i) for i in input().split()]

a=[int(i) for i in input().split()]



if(n==1):

    print((a[0]-x))

    exit()

ope=0

if(a[0]>x):

    ope+=a[0]-x

    a[0]=x



for i in range(n-1):

    c=a[i]+a[i+1]

    if(c>x):

        a[i+1]-=c-x

        ope+=c-x

print(ope)
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
count = 0
if a[0] > x:
    count = a[0] - x
    a[0] = x
for ind, i in enumerate(a):
    if ind == len(a) - 1:
        break
    s = i + a[ind + 1]
    if s > x:
        count += s - x
        a[ind + 1] -= s - x
        # s=i+a[ind+1]
print(count)

n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
if n == 1:
    print((a[0] - x))
    exit()
ope = 0
if a[0] > x:
    ope += a[0] - x
    a[0] = x
for i in range(n - 1):
    c = a[i] + a[i + 1]
    if c > x:
        a[i + 1] -= c - x
        ope += c - x
print(ope)

-count = 0 +if n == 1: +    print((a[0] - x)) +    exit() +ope = 0 -    count = a[0] - x +    ope += a[0] - x -for ind, i in enumerate(a): -    if ind == len(a) - 1: -        break -    s = i + a[ind + 1] -    if s > x: -        count += s - x -        a[ind + 1] -= s - x -        # s=i+a[ind+1] -print(count) +for i in range(n - 1): +    c = a[i] + a[i + 1] +    if c > x: +        a[i + 1] -= c - x +        ope += c - x +print(ope)