fun main(args: Array<String>) {
    val (n,x)= readLine()!!.split(" ").map { it.toInt() }
    val a= readLine()!!.split(" ").map { it.toLong() }.toTypedArray()

    var eatSum=0L
    eatSum += Math.max(0L, a[0]-x)
    a[0] -= eatSum
    (1..a.lastIndex).forEach { i->
        val eat = Math.max(0L, a[i]+a[i-1]-x)
        eatSum += eat
        a[i] -= eat
    }
    println(eatSum)
}