
fun next() = readLine()!!.split(" ")

fun main(args: Array<String>) {
    val (range_s, sum_s) = next()
    val range = range_s.toInt()
    val sumLimit = sum_s.toLong()
    val array = next().map { it.toLong() }.toMutableList()

    var result = 0L
    for (i in 1 until range) {
        var a1 = array[i - 1]
        var a2 = array[i]
        if (a1 + a2 <= sumLimit) {
            continue
        }
        if (a1 >= sumLimit) {
            result += a1 + a2 - sumLimit
            a2 = 0L
            a1 = sumLimit
        } else {
            result += a2 - (sumLimit - a1)
            a2 = sumLimit - a1
        }
        array[i - 1] = a1
        array[i] = a2
    }
    println(result)
}
