#003

N,x=input().split(" ")

s = input().split(" ")

list = []

for i in range(int(N)):

    list.append(int(s[i]))

count = 0



if(list[0]>int(x)):

    count+=list[0]-int(x)

    list[0]-=list[0]-int(x)



for i in range(1,int(N)):

    temp = list[i]+list[i-1]

    if(temp>int(x)):

        count+=temp-int(x)

        list[i]-=temp-int(x)        

print(count) 
#003

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

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

count = 0 

for i in range(N):

    if(i==0):

        if list[i]>x:

            temp = list[i]-x

            count+=temp

            list[i]-=temp

    else:

        temp = list[i]+list[i-1]-x

        if(temp>0):

            count+=temp

            list[i]-=temp    

print(count)
# 003
N, x = input().split(" ")
s = input().split(" ")
list = []
for i in range(int(N)):
    list.append(int(s[i]))
count = 0
if list[0] > int(x):
    count += list[0] - int(x)
    list[0] -= list[0] - int(x)
for i in range(1, int(N)):
    temp = list[i] + list[i - 1]
    if temp > int(x):
        count += temp - int(x)
        list[i] -= temp - int(x)
print(count)

# 003
N, x = [int(i) for i in input().split(" ")]
list = [int(i) for i in input().split(" ")]
count = 0
for i in range(N):
    if i == 0:
        if list[i] > x:
            temp = list[i] - x
            count += temp
            list[i] -= temp
    else:
        temp = list[i] + list[i - 1] - x
        if temp > 0:
            count += temp
            list[i] -= temp
print(count)

-N, x = input().split(" ") -s = input().split(" ") -list = [] -for i in range(int(N)): -    list.append(int(s[i])) +N, x = [int(i) for i in input().split(" ")] +list = [int(i) for i in input().split(" ")] -if list[0] > int(x): -    count += list[0] - int(x) -    list[0] -= list[0] - int(x) -for i in range(1, int(N)): -    temp = list[i] + list[i - 1] -    if temp > int(x): -        count += temp - int(x) -        list[i] -= temp - int(x) +for i in range(N): +    if i == 0: +        if list[i] > x: +            temp = list[i] - x +            count += temp +            list[i] -= temp +    else: +        temp = list[i] + list[i - 1] - x +        if temp > 0: +            count += temp +            list[i] -= temp