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

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

sum_a = sum(a)



for i in range(1,N):

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

        if a[i] > (a[i] + a[i-1]) - x:

            # cnt += (a[i] + a[i-1]) - x

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

            continue

        else:

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

            a[i] = 0

            a[i-1] = x

            continue



print((sum_a - sum(a)))
def main():

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

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

    cnt = 0

    for i in range(1,N):

        tmp = A[i] + A[i-1]

        if tmp > x:

            tmp -= x

            cnt += tmp

            A[i] = max(0, A[i]-tmp)



    print(cnt)



if __name__ == "__main__":

    main()
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
sum_a = sum(a)
for i in range(1, N):
    if a[i - 1] + a[i] > x:
        if a[i] > (a[i] + a[i - 1]) - x:
            # cnt += (a[i] + a[i-1]) - x
            a[i] -= (a[i] + a[i - 1]) - x
            continue
        else:
            # cnt += a[i-1] - x
            a[i] = 0
            a[i - 1] = x
            continue
print((sum_a - sum(a)))

def main():
    N, x = list(map(int, input().split()))
    A = list(map(int, input().split()))
    cnt = 0
    for i in range(1, N):
        tmp = A[i] + A[i - 1]
        if tmp > x:
            tmp -= x
            cnt += tmp
            A[i] = max(0, A[i] - tmp)
    print(cnt)


if __name__ == "__main__":
    main()

-N, x = list(map(int, input().split())) -a = list(map(int, input().split())) -sum_a = sum(a) -for i in range(1, N): -    if a[i - 1] + a[i] > x: -        if a[i] > (a[i] + a[i - 1]) - x: -            # cnt += (a[i] + a[i-1]) - x -            a[i] -= (a[i] + a[i - 1]) - x -            continue -        else: -            # cnt += a[i-1] - x -            a[i] = 0 -            a[i - 1] = x -            continue -print((sum_a - sum(a))) +def main(): +    N, x = list(map(int, input().split())) +    A = list(map(int, input().split())) +    cnt = 0 +    for i in range(1, N): +        tmp = A[i] + A[i - 1] +        if tmp > x: +            tmp -= x +            cnt += tmp +            A[i] = max(0, A[i] - tmp) +    print(cnt) + + +if __name__ == "__main__": +    main()