fun main(args: Array<String>) {
    abc048c()
}

fun abc048c() {
    val (n, x) = readLine()!!.split(' ').map { it.toLong() }
    val aList = readLine()!!.split(' ').map { it.toLong() }.toLongArray()
    val initValue = aList.copyOf()

    var answer = 0L
    for (i in 0 until aList.lastIndex) {
        val value = aList[i]
        val diff = value + aList[i + 1] - x
        if (diff > 0) {
            val remain = diff - aList[i + 1]
            aList[i + 1] = Math.max(0, aList[i + 1] - diff)
            if (remain > 0) aList[i] -= remain
            answer += diff
        }
    }

    println(answer)
}
