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

    var ans = 0
    if(a(0) > x){
      ans += a(0)-x
      a(0) = x
    }

    for(i <- 1 to N-1){
      if(a(i-1) + a(i) > x){
        val d = a(i-1)+a(i) - x
        ans += d
        a(i) -= d
        if(a(i)<0) a(i) = 0
      }
    }

    println(ans)
  }
}
