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

    // 前から詰めていけばよいのでは？？
    // -> 計算を用意してO(1) で各ステップ完了できればOK
    var cnt = 0L

    for (i in 0 until n) {
        val minus = Math.min(A[i], B[i])
        A[i] -= minus
        B[i] -= minus
        cnt += minus

        val minusPost = Math.min(A[i + 1], B[i])
        A[i + 1] -= minusPost
        B[i] -= minusPost
        cnt += minusPost
    }

    println(cnt)
}