let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init (n + 1) @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let bs = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun b -> b in
  let sum = ref 0 in
  for i = 0 to n - 1 do
    for d = 0 to 1 do
      let n = min as_.(i + d) bs.(i) in
      sum := !sum + n;
      as_.(i + d) <- as_.(i + d) - n;
      bs.(i) <- bs.(i) - n
    done
  done;
  Printf.printf "%d\n" !sum

