fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val monsters = readLine()!!.split(" ").map { it.toInt() }
    val braves = readLine()!!.split(" ").map { it.toInt() }

    var total: Long = 0
    var morasi = monsters[0]

    (0 until n).forEach { i ->
        val brave = Brave(braves[i])
        total += brave.slay(morasi)
        val ns = brave.slay(monsters[i+1])
        total += ns
        morasi = monsters[i+1] - ns
    }
    print(total)
}

data class Brave(var power: Int) {
    fun slay(enemy: Int): Int {
        val currentPow = power
        return if (enemy >= power) {
            power = 0
            currentPow
        } else {
            power = currentPow - enemy
            enemy
        }
    }
}