fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main() {
    val (n, x) = longList()
    val a = longList()
    var p = 0L
    var e = 0L
    repeat(n.toInt()) { i ->
        val aa = a[i]
        if (aa + p > x) {
            val d = aa + p - x
            e += d
            p = aa - d
        } else {
            p = aa
        }
    }
    println(e.toString())
}
