fun main(args: Array<String>) {
    val n:String? = readLine()
    val monstersInput:String? = readLine()
    val saversInput:String? = readLine()

    if (n == null || monstersInput == null || saversInput == null) return

    val monsters:List<String> = monstersInput.trim().split(" ")
    val savers:List<String> = saversInput.trim().split(" ")

    var count:Long = 0
    var nextAttack:Long = 0
    for (i in savers.indices) {
        var monster = monsters[i].toLong()
        val saver = savers[i].toLong()
        if (nextAttack > 0) {
            if (monster < nextAttack) {
                count += monster
                monster = 0
            } else {
                count += nextAttack
                monster -= nextAttack
            }
        }

        if (monster < saver) {
            count += monster
            nextAttack = saver - monster
        } else {
            count += saver
            nextAttack = 0
        }
    }

    if (nextAttack > 0) {
        val lastMonster = monsters.last().toLong()
        count += if (lastMonster < nextAttack) lastMonster else nextAttack
    }

    println(count)

}