import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] A = new long[n+1];
		long res = 0;
		for(int i = 0; i < n+1; i++){
			A[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++){
			long d = sc.nextInt();
			if(A[i] + A[i+1] >= d){
				res += d;
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
			}
			else{
				res += A[i] + A[i+1];
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
				if(A[i+1] < 0) A[i+1] = 0;
			}
		}
		System.out.println(res);
	}
} import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] A = new long[n+1];
		long res = 0;
		for(int i = 0; i < n+1; i++){
			A[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++){
			long d = sc.nextInt();
			if(A[i] + A[i+1] >= d){
				res += d;
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
			}
			else{
				res += A[i] + A[i+1];
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
				if(A[i+1] < 0) A[i+1] = 0;
			}
		}
		System.out.println(res);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] A = new long[n+1];
		long res = 0;
		for(int i = 0; i < n+1; i++){
			A[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++){
			long d = sc.nextInt();
			if(A[i] + A[i+1] >= d){
				res += d;
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
			}
			else{
				res += A[i] + A[i+1];
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
				if(A[i+1] < 0) A[i+1] = 0;
			}
		}
		System.out.println(res);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] A = new long[n+1];
		long res = 0;
		for(int i = 0; i < n+1; i++){
			A[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++){
			long d = sc.nextInt();
			if(A[i] + A[i+1] >= d){
				res += d;
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
			}
			else{
				res += A[i] + A[i+1];
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
				if(A[i+1] < 0) A[i+1] = 0;
			}
		}
		System.out.println(res);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc long[] A = new long[n+1]; A new long[n+1] n+1 n 1 long res = 0; res 0 for(int i = 0; i < n+1; i++){
			A[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n+1 i n+1 n 1 i++ i++ i {
			A[i] = sc.nextInt();
		} {
			A[i] = sc.nextInt();
		} A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc for(int i = 0; i < n; i++){
			long d = sc.nextInt();
			if(A[i] + A[i+1] >= d){
				res += d;
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
			}
			else{
				res += A[i] + A[i+1];
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
				if(A[i+1] < 0) A[i+1] = 0;
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			long d = sc.nextInt();
			if(A[i] + A[i+1] >= d){
				res += d;
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
			}
			else{
				res += A[i] + A[i+1];
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
				if(A[i+1] < 0) A[i+1] = 0;
			}
		} {
			long d = sc.nextInt();
			if(A[i] + A[i+1] >= d){
				res += d;
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
			}
			else{
				res += A[i] + A[i+1];
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
				if(A[i+1] < 0) A[i+1] = 0;
			}
		} long d = sc.nextInt(); d sc.nextInt() sc.nextInt sc if(A[i] + A[i+1] >= d){
				res += d;
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
			}
			else{
				res += A[i] + A[i+1];
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
				if(A[i+1] < 0) A[i+1] = 0;
			} A[i] + A[i+1] >= d A[i] + A[i+1] A[i] A i A[i+1] A i+1 i 1 d {
				res += d;
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
			} res += d res d A[i] -= d A[i] A i d if(A[i] < 0) A[i+1] += A[i]; A[i] < 0 A[i] A i 0 A[i+1] += A[i] A[i+1] A i+1 i 1 A[i] A i {
				res += A[i] + A[i+1];
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
				if(A[i+1] < 0) A[i+1] = 0;
			} res += A[i] + A[i+1] res A[i] + A[i+1] A[i] A i A[i+1] A i+1 i 1 A[i] -= d A[i] A i d if(A[i] < 0) A[i+1] += A[i]; A[i] < 0 A[i] A i 0 A[i+1] += A[i] A[i+1] A i+1 i 1 A[i] A i if(A[i+1] < 0) A[i+1] = 0; A[i+1] < 0 A[i+1] A i+1 i 1 0 A[i+1] = 0 A[i+1] A i+1 i 1 0 System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] A = new long[n+1];
		long res = 0;
		for(int i = 0; i < n+1; i++){
			A[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++){
			long d = sc.nextInt();
			if(A[i] + A[i+1] >= d){
				res += d;
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
			}
			else{
				res += A[i] + A[i+1];
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
				if(A[i+1] < 0) A[i+1] = 0;
			}
		}
		System.out.println(res);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] A = new long[n+1];
		long res = 0;
		for(int i = 0; i < n+1; i++){
			A[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++){
			long d = sc.nextInt();
			if(A[i] + A[i+1] >= d){
				res += d;
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
			}
			else{
				res += A[i] + A[i+1];
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
				if(A[i+1] < 0) A[i+1] = 0;
			}
		}
		System.out.println(res);
	}
} Main
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] A = new long[n+1];
		long res = 0;
		for(int i = 0; i < n+1; i++){
			A[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++){
			long d = sc.nextInt();
			if(A[i] + A[i+1] >= d){
				res += d;
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
			}
			else{
				res += A[i] + A[i+1];
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
				if(A[i+1] < 0) A[i+1] = 0;
			}
		}
		System.out.println(res);
	}
}
