from collections import defaultdict





def main():

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

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

    ans = 0

    for i in range(len(a_list)):

        d = max(0, a_list[i] - x)

        a_list[i] -= d

        ans += d



    for i in range(1, len(a_list)):

        total = a_list[i - 1] + a_list[i]

        if total > x:

            d = total - x

            a_list[i] -= d

            ans += d



    print(ans)





if __name__ == '__main__':

    main()

from collections import defaultdict





def main():

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

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



    pre_total = sum(a_list)



    a_list = [min(a, x) for a in a_list]

    for i in range(1, len(a_list)):

        t = a_list[i - 1] + a_list[i]

        a_list[i] -= max(0, t - x)



    print((pre_total - sum(a_list)))





if __name__ == '__main__':

    main()

from collections import defaultdict


def main():
    N, x = list(map(int, input().split()))
    a_list = list(map(int, input().split()))
    ans = 0
    for i in range(len(a_list)):
        d = max(0, a_list[i] - x)
        a_list[i] -= d
        ans += d
    for i in range(1, len(a_list)):
        total = a_list[i - 1] + a_list[i]
        if total > x:
            d = total - x
            a_list[i] -= d
            ans += d
    print(ans)


if __name__ == "__main__":
    main()

from collections import defaultdict


def main():
    N, x = list(map(int, input().split()))
    a_list = list(map(int, input().split()))
    pre_total = sum(a_list)
    a_list = [min(a, x) for a in a_list]
    for i in range(1, len(a_list)):
        t = a_list[i - 1] + a_list[i]
        a_list[i] -= max(0, t - x)
    print((pre_total - sum(a_list)))


if __name__ == "__main__":
    main()

-    ans = 0 -    for i in range(len(a_list)): -        d = max(0, a_list[i] - x) -        a_list[i] -= d -        ans += d +    pre_total = sum(a_list) +    a_list = [min(a, x) for a in a_list] -        total = a_list[i - 1] + a_list[i] -        if total > x: -            d = total - x -            a_list[i] -= d -            ans += d -    print(ans) +        t = a_list[i - 1] + a_list[i] +        a_list[i] -= max(0, t - x) +    print((pre_total - sum(a_list)))