import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long[] a = new long[n + 1];
        long[] b = new long[n];
        long sum = 0;
        for(int i = 0; i < n + 1; i++){
            a[i] = scan.nextInt();
            sum += a[i];
        }
        for(int i = 0; i < n; i++) b[i] = scan.nextInt();
        for(int i = 0; i < n; i++){
            if(a[i] <= b[i]){
                a[i + 1] = Math.max(0, a[i + 1] - b[i] + a[i]);
                a[i] = 0;
            }else{
                a[i] -= b[i];
            }
        }
        long out = 0;
        for(int i = 0; i < n + 1; i++) out += a[i];
        System.out.println(sum - out);
        scan.close();
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long[] a = new long[n + 1];
        long[] b = new long[n];
        long sum = 0;
        for(int i = 0; i < n + 1; i++){
            a[i] = scan.nextInt();
            sum += a[i];
        }
        for(int i = 0; i < n; i++) b[i] = scan.nextInt();
        for(int i = 0; i < n; i++){
            if(a[i] <= b[i]){
                a[i + 1] = Math.max(0, a[i + 1] - b[i] + a[i]);
                a[i] = 0;
            }else{
                a[i] -= b[i];
            }
        }
        long out = 0;
        for(int i = 0; i < n + 1; i++) out += a[i];
        System.out.println(sum - out);
        scan.close();
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long[] a = new long[n + 1];
        long[] b = new long[n];
        long sum = 0;
        for(int i = 0; i < n + 1; i++){
            a[i] = scan.nextInt();
            sum += a[i];
        }
        for(int i = 0; i < n; i++) b[i] = scan.nextInt();
        for(int i = 0; i < n; i++){
            if(a[i] <= b[i]){
                a[i + 1] = Math.max(0, a[i + 1] - b[i] + a[i]);
                a[i] = 0;
            }else{
                a[i] -= b[i];
            }
        }
        long out = 0;
        for(int i = 0; i < n + 1; i++) out += a[i];
        System.out.println(sum - out);
        scan.close();
    } main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long[] a = new long[n + 1];
        long[] b = new long[n];
        long sum = 0;
        for(int i = 0; i < n + 1; i++){
            a[i] = scan.nextInt();
            sum += a[i];
        }
        for(int i = 0; i < n; i++) b[i] = scan.nextInt();
        for(int i = 0; i < n; i++){
            if(a[i] <= b[i]){
                a[i + 1] = Math.max(0, a[i + 1] - b[i] + a[i]);
                a[i] = 0;
            }else{
                a[i] -= b[i];
            }
        }
        long out = 0;
        for(int i = 0; i < n + 1; i++) out += a[i];
        System.out.println(sum - out);
        scan.close();
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan long[] a = new long[n + 1]; a new long[n + 1] n + 1 n 1 long[] b = new long[n]; b new long[n] n long sum = 0; sum 0 for(int i = 0; i < n + 1; i++){
            a[i] = scan.nextInt();
            sum += a[i];
        } int i = 0; int i = 0; i 0 i < n + 1 i n + 1 n 1 i++ i++ i {
            a[i] = scan.nextInt();
            sum += a[i];
        } {
            a[i] = scan.nextInt();
            sum += a[i];
        } a[i] = scan.nextInt() a[i] a i scan.nextInt() scan.nextInt scan sum += a[i] sum a[i] a i for(int i = 0; i < n; i++) b[i] = scan.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i b[i] = scan.nextInt(); b[i] = scan.nextInt() b[i] b i scan.nextInt() scan.nextInt scan for(int i = 0; i < n; i++){
            if(a[i] <= b[i]){
                a[i + 1] = Math.max(0, a[i + 1] - b[i] + a[i]);
                a[i] = 0;
            }else{
                a[i] -= b[i];
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if(a[i] <= b[i]){
                a[i + 1] = Math.max(0, a[i + 1] - b[i] + a[i]);
                a[i] = 0;
            }else{
                a[i] -= b[i];
            }
        } {
            if(a[i] <= b[i]){
                a[i + 1] = Math.max(0, a[i + 1] - b[i] + a[i]);
                a[i] = 0;
            }else{
                a[i] -= b[i];
            }
        } if(a[i] <= b[i]){
                a[i + 1] = Math.max(0, a[i + 1] - b[i] + a[i]);
                a[i] = 0;
            }else{
                a[i] -= b[i];
            } a[i] <= b[i] a[i] a i b[i] b i {
                a[i + 1] = Math.max(0, a[i + 1] - b[i] + a[i]);
                a[i] = 0;
            } a[i + 1] = Math.max(0, a[i + 1] - b[i] + a[i]) a[i + 1] a i + 1 i 1 Math.max(0, a[i + 1] - b[i] + a[i]) Math.max Math 0 a[i + 1] - b[i] + a[i] a[i + 1] - b[i] a[i + 1] a i + 1 i 1 b[i] b i a[i] a i a[i] = 0 a[i] a i 0 {
                a[i] -= b[i];
            } a[i] -= b[i] a[i] a i b[i] b i long out = 0; out 0 for(int i = 0; i < n + 1; i++) out += a[i]; int i = 0; int i = 0; i 0 i < n + 1 i n + 1 n 1 i++ i++ i out += a[i]; out += a[i] out a[i] a i System.out.println(sum - out) System.out.println System.out System System.out sum - out sum out scan.close() scan.close scan String[] args args public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long[] a = new long[n + 1];
        long[] b = new long[n];
        long sum = 0;
        for(int i = 0; i < n + 1; i++){
            a[i] = scan.nextInt();
            sum += a[i];
        }
        for(int i = 0; i < n; i++) b[i] = scan.nextInt();
        for(int i = 0; i < n; i++){
            if(a[i] <= b[i]){
                a[i + 1] = Math.max(0, a[i + 1] - b[i] + a[i]);
                a[i] = 0;
            }else{
                a[i] -= b[i];
            }
        }
        long out = 0;
        for(int i = 0; i < n + 1; i++) out += a[i];
        System.out.println(sum - out);
        scan.close();
    }
} public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long[] a = new long[n + 1];
        long[] b = new long[n];
        long sum = 0;
        for(int i = 0; i < n + 1; i++){
            a[i] = scan.nextInt();
            sum += a[i];
        }
        for(int i = 0; i < n; i++) b[i] = scan.nextInt();
        for(int i = 0; i < n; i++){
            if(a[i] <= b[i]){
                a[i + 1] = Math.max(0, a[i + 1] - b[i] + a[i]);
                a[i] = 0;
            }else{
                a[i] -= b[i];
            }
        }
        long out = 0;
        for(int i = 0; i < n + 1; i++) out += a[i];
        System.out.println(sum - out);
        scan.close();
    }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long[] a = new long[n + 1];
        long[] b = new long[n];
        long sum = 0;
        for(int i = 0; i < n + 1; i++){
            a[i] = scan.nextInt();
            sum += a[i];
        }
        for(int i = 0; i < n; i++) b[i] = scan.nextInt();
        for(int i = 0; i < n; i++){
            if(a[i] <= b[i]){
                a[i + 1] = Math.max(0, a[i + 1] - b[i] + a[i]);
                a[i] = 0;
            }else{
                a[i] -= b[i];
            }
        }
        long out = 0;
        for(int i = 0; i < n + 1; i++) out += a[i];
        System.out.println(sum - out);
        scan.close();
    }
}