import java.util.Scanner

object Main {
  def resolve(N: Int, x: Int, a: Array[Int]): Long = {
    // 左から２個ずつペア(i, i + 1) i+1を先に減らしていく貪欲法でいける
    var res: Long = 0
    for {
      i <- 0 until N - 1
    } {
      val r1 = a(i + 0) + a(i + 1) - x
      val sub1 = if (r1 > 0) math.min(r1, a(i + 1)) else 0
      val r0 = r1 - sub1
      val sub0 = if (r0 > 0) math.min(r0, a(i + 0)) else 0

      a(i + 1) -= sub1
      a(i + 0) -= sub0

      res += sub1 + sub0
    }
    res
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val N = sc.nextInt()
    val x = sc.nextInt()
    val a = Array.ofDim[Int](N)
    a.indices foreach (i => a(i) = sc.nextInt())
    println(resolve(N, x, a))
  }
}
