def main():

    N, x, *a = list(map(int, open(0).read().split()))

    ans = 0

    pre = a[0]

    for i in range(1, N):

        if x < pre + a[i]:

            cur = pre + a[i] - x

            ans += cur

            a[i] = a[i] - cur if cur < a[i] else 0

        pre = a[i]

    print(ans)

    return





main()

def main():

    N, x, *a = list(map(int, open(0).read().split()))

    ans = a[0] - x if x < a[0] else 0

    pre = min(a[0], x)

    for i in range(1, N):

        dif = pre + a[i] - x

        if 0 < dif:

            ans += dif

            a[i] -= dif

        pre = a[i]

    print(ans)

    return





main()

def main():
    N, x, *a = list(map(int, open(0).read().split()))
    ans = 0
    pre = a[0]
    for i in range(1, N):
        if x < pre + a[i]:
            cur = pre + a[i] - x
            ans += cur
            a[i] = a[i] - cur if cur < a[i] else 0
        pre = a[i]
    print(ans)
    return


main()

def main():
    N, x, *a = list(map(int, open(0).read().split()))
    ans = a[0] - x if x < a[0] else 0
    pre = min(a[0], x)
    for i in range(1, N):
        dif = pre + a[i] - x
        if 0 < dif:
            ans += dif
            a[i] -= dif
        pre = a[i]
    print(ans)
    return


main()

-    ans = 0 -    pre = a[0] +    ans = a[0] - x if x < a[0] else 0 +    pre = min(a[0], x) -        if x < pre + a[i]: -            cur = pre + a[i] - x -            ans += cur -            a[i] = a[i] - cur if cur < a[i] else 0 +        dif = pre + a[i] - x +        if 0 < dif: +            ans += dif +            a[i] -= dif