import io.{StdIn => in}

object Main extends App {
  val Array(n, x) = in.readLine.split(" ").map(_.toLong)
  val a = in.readLine.split(" ").map(_.toLong)
  val ans = a.tail./:(0L,a.head)((acc,ai) => {
    val bi = acc._2
    val gap = if(bi + ai > x) bi + ai - x else 0
    val adj = if(ai < gap) ai - gap else 0
    (acc._1 + gap, ai - gap - adj)
  })._1
  println(ans)
}