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

    var ans = 0L
    var rm = Math.max(0, (boxes.last() + boxes[boxes.lastIndex-1])-x)
    ans += rm
    if(boxes[boxes.lastIndex-1] >= rm) {
        boxes[boxes.lastIndex-1] -= rm
    } else {
        rm -= boxes[boxes.lastIndex-1]
        boxes[boxes.lastIndex] -= rm
        boxes[boxes.lastIndex-1] = 0
    }
    rm = Math.max(0, (boxes[0] + boxes[1])-x)
    ans += rm
    if(boxes[1] >= rm) {
        boxes[1] -= rm
    } else {
        rm -= boxes[1]
        boxes[0] -= rm
        boxes[1] = 0
    }

    for(i in (1..boxes.lastIndex-1)) {
        rm = Math.max(0,(boxes[i] + boxes[i+1])-x)
        ans += rm
        if(boxes[i+1] >= rm) {
            boxes[i+1] -= rm
        } else {
            rm -= boxes[i+1]
            boxes[i] -= rm
            boxes[i+1] = 0
        }
    }
    println(ans)
}