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

    var eaten = 0L
    for (i in 0 until n-1) {
        if (aa[i] > x) {
            val diff = aa[i] - x
            eaten += diff
            aa[i] -= diff
        }
        if (aa[i] + aa[i+1] > x) {
            val diff = (aa[i] + aa[i+1]) - x
            eaten += diff
            aa[i+1] -= diff
        }
    }

    println(eaten)
}