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