import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)
    val n, x = sc.nextInt()
    val as = Array.fill(n)(sc.nextLong())

    val temp = as.map(a => if (a > x) x else a)
    debug(temp.mkString(" "))
    val sum = as.sum - temp.sum
    debug(sum)

    var tmp = 0L

    for (i <- temp.indices) {
      if (i != 0) {
        if (temp(i) + temp(i - 1) > x) {
          val over = temp(i) + temp(i - 1) - x
          tmp += over
          temp(i) -= over
        }
      }
    }

    println(sum + tmp)
    debug(temp.mkString(" "))

  }

  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }
}
