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

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



count = 0

previous = 0



for i in a:

    if i + previous > x: 

        excess = i + previous - x

        count += excess

        previous = x - previous

    else: # if not exceeding x.

        previous = i



print(count)



import sys



n, x, *a = list(map(int, sys.stdin.read().split()))



def main():

    cnt = 0

    lim = x

    for c in a:

        if c > lim:

            cnt += c - lim

            lim = x - lim

        else:

            lim = x - c

            

    return cnt



if __name__ == '__main__':

    ans = main()

    print(ans)
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
count = 0
previous = 0
for i in a:
    if i + previous > x:
        excess = i + previous - x
        count += excess
        previous = x - previous
    else:  # if not exceeding x.
        previous = i
print(count)

import sys

n, x, *a = list(map(int, sys.stdin.read().split()))


def main():
    cnt = 0
    lim = x
    for c in a:
        if c > lim:
            cnt += c - lim
            lim = x - lim
        else:
            lim = x - c
    return cnt


if __name__ == "__main__":
    ans = main()
    print(ans)

-n, x = [int(i) for i in input().split()] -a = [int(i) for i in input().split()] -count = 0 -previous = 0 -for i in a: -    if i + previous > x: -        excess = i + previous - x -        count += excess -        previous = x - previous -    else:  # if not exceeding x. -        previous = i -print(count) +import sys + +n, x, *a = list(map(int, sys.stdin.read().split())) + + +def main(): +    cnt = 0 +    lim = x +    for c in a: +        if c > lim: +            cnt += c - lim +            lim = x - lim +        else: +            lim = x - c +    return cnt + + +if __name__ == "__main__": +    ans = main() +    print(ans)