object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn._
    val Array(n, x) = readLine().split(' ').map(_.toInt)
    val a = 0 +: readLine().split(' ').map(_.toInt)

    var num = 0
    for (i <- 0 until a.length - 1) {
      val sum = a(i) + a(i+1)
      if (sum > x) {
        a(i+1) -= sum - x
        num += sum - x
      }
    }

    println(num)
  }
}
