import sys



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

res1 = res2 = 0

lst2 = [0] + lst1

lst1.append(0)

for i in range(n):

  tmpsum = lst2[i] + lst2[i + 1]

  if tmpsum > x:

    res1 += tmpsum - x

    lst2[i + 1] -= tmpsum - x



for i in range(n, 0, -1):

  tmpsum = lst1[i] + lst1[i - 1]

  if tmpsum > x:

    res2 += tmpsum - x

    lst1[i - 1] -= tmpsum - x  

print((min(res1, res2)))
import sys



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

res1 = 0

lst2 = [0] + lst1

lst1.append(0)

for i in range(n):

  tmpsum = lst2[i] + lst2[i + 1]

  if tmpsum > x:

    res1 += tmpsum - x

    lst2[i + 1] -= tmpsum - x



print(res1)
import sys

n, x, *lst1 = list(map(int, sys.stdin.read().split()))
res1 = res2 = 0
lst2 = [0] + lst1
lst1.append(0)
for i in range(n):
    tmpsum = lst2[i] + lst2[i + 1]
    if tmpsum > x:
        res1 += tmpsum - x
        lst2[i + 1] -= tmpsum - x
for i in range(n, 0, -1):
    tmpsum = lst1[i] + lst1[i - 1]
    if tmpsum > x:
        res2 += tmpsum - x
        lst1[i - 1] -= tmpsum - x
print((min(res1, res2)))

import sys

n, x, *lst1 = list(map(int, sys.stdin.read().split()))
res1 = 0
lst2 = [0] + lst1
lst1.append(0)
for i in range(n):
    tmpsum = lst2[i] + lst2[i + 1]
    if tmpsum > x:
        res1 += tmpsum - x
        lst2[i + 1] -= tmpsum - x
print(res1)

-res1 = res2 = 0 +res1 = 0 -for i in range(n, 0, -1): -    tmpsum = lst1[i] + lst1[i - 1] -    if tmpsum > x: -        res2 += tmpsum - x -        lst1[i - 1] -= tmpsum - x -print((min(res1, res2))) +print(res1)