fun main(args: Array<String>) {
    val (n, x) = readLine()!!.split(" ").map(String::toInt)
    val aa = readLine()!!.split(" ").map(String::toInt)
    val a = IntArray(n) { i -> aa[i] }
    var result = 0L
    for (i in 0 until n - 1) {
        val box1 = a[i]
        val box2 = a[i + 1]
        val d = box1 + box2 - x
        if (0 < d) {
            a[i + 1] = if (box2 < d) 0 else box2 - d
            result += d
        }
    }
    println(result)
}
