import sys



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

a = [0] + a



def main():

  tot = 0

  for i in range(1, n + 1):

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

      tot += a[i] + a[i-1] - x

      a[i] = x - a[i-1]

  print(tot)



if __name__ ==  '__main__':

  main()
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

  print(cnt)



if __name__ ==  '__main__':

  main()
import sys

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


def main():
    tot = 0
    for i in range(1, n + 1):
        if a[i] + a[i - 1] > x:
            tot += a[i] + a[i - 1] - x
            a[i] = x - a[i - 1]
    print(tot)


if __name__ == "__main__":
    main()

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
    print(cnt)


if __name__ == "__main__":
    main()

-a = [0] + a -    tot = 0 -    for i in range(1, n + 1): -        if a[i] + a[i - 1] > x: -            tot += a[i] + a[i - 1] - x -            a[i] = x - a[i - 1] -    print(tot) +    cnt = 0 +    lim = x +    for c in a: +        if c > lim: +            cnt += c - lim +            lim = x - lim +        else: +            lim = x - c +    print(cnt)