[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let n = read int64
    let cs = reads int64
    let ds = reads int64

    let rec loop acc rem xs ys =
        match (xs, ys) with
        | ([x], []) ->
            acc + min x rem
        | (x :: xs, y :: ys) ->
            let x' = max 0L (x - rem)
            let rem' = max 0L (y - x')
            let a = min x (y + rem)
            loop (acc + a) rem' xs ys

    loop 0L 0L cs ds
    |> printfn "%i"
    0