import java.util.Scanner;

public class Main {
    static int N;
    static long[] a;
    static long[] b;

    private static void init() {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        a = new long[N + 1];
        b = new long[N];
        for(int i = 0; i <= N; i++) {
            a[i] = scanner.nextLong();
        }
        for(int i = 0; i < N; i++) {
            b[i] = scanner.nextLong();
        }
        scanner.close();
    }


    public static void main(String[] args) {
        init();

        long kill = 0;
        for(int i = 0; i < N; i++) {
            long remainPowser = 0;
            if(b[i] > a[i]) {
                remainPowser = Math.min(b[i] - a[i], a[i + 1]);
                if(a[i + 1] > remainPowser) {
                    a[i + 1] = a[i + 1] - remainPowser;
                } else {
                    a[i + 1] = Math.max(a[i + 1] - (b[i] - a[i]), 0);
                }
            }
            kill += Math.min(a[i], b[i]) + remainPowser;
        }

        System.out.println(kill);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    static int N;
    static long[] a;
    static long[] b;

    private static void init() {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        a = new long[N + 1];
        b = new long[N];
        for(int i = 0; i <= N; i++) {
            a[i] = scanner.nextLong();
        }
        for(int i = 0; i < N; i++) {
            b[i] = scanner.nextLong();
        }
        scanner.close();
    }


    public static void main(String[] args) {
        init();

        long kill = 0;
        for(int i = 0; i < N; i++) {
            long remainPowser = 0;
            if(b[i] > a[i]) {
                remainPowser = Math.min(b[i] - a[i], a[i + 1]);
                if(a[i + 1] > remainPowser) {
                    a[i + 1] = a[i + 1] - remainPowser;
                } else {
                    a[i + 1] = Math.max(a[i + 1] - (b[i] - a[i]), 0);
                }
            }
            kill += Math.min(a[i], b[i]) + remainPowser;
        }

        System.out.println(kill);
    }
} Main static int N; N static long[] a; a static long[] b; b private static void init() {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        a = new long[N + 1];
        b = new long[N];
        for(int i = 0; i <= N; i++) {
            a[i] = scanner.nextLong();
        }
        for(int i = 0; i < N; i++) {
            b[i] = scanner.nextLong();
        }
        scanner.close();
    } init {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        a = new long[N + 1];
        b = new long[N];
        for(int i = 0; i <= N; i++) {
            a[i] = scanner.nextLong();
        }
        for(int i = 0; i < N; i++) {
            b[i] = scanner.nextLong();
        }
        scanner.close();
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) N = scanner.nextInt() N scanner.nextInt() scanner.nextInt scanner a = new long[N + 1] a new long[N + 1] N + 1 N 1 b = new long[N] b new long[N] N for(int i = 0; i <= N; i++) {
            a[i] = scanner.nextLong();
        } int i = 0; int i = 0; i 0 i <= N i N i++ i++ i {
            a[i] = scanner.nextLong();
        } {
            a[i] = scanner.nextLong();
        } a[i] = scanner.nextLong() a[i] a i scanner.nextLong() scanner.nextLong scanner for(int i = 0; i < N; i++) {
            b[i] = scanner.nextLong();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            b[i] = scanner.nextLong();
        } {
            b[i] = scanner.nextLong();
        } b[i] = scanner.nextLong() b[i] b i scanner.nextLong() scanner.nextLong scanner scanner.close() scanner.close scanner public static void main(String[] args) {
        init();

        long kill = 0;
        for(int i = 0; i < N; i++) {
            long remainPowser = 0;
            if(b[i] > a[i]) {
                remainPowser = Math.min(b[i] - a[i], a[i + 1]);
                if(a[i + 1] > remainPowser) {
                    a[i + 1] = a[i + 1] - remainPowser;
                } else {
                    a[i + 1] = Math.max(a[i + 1] - (b[i] - a[i]), 0);
                }
            }
            kill += Math.min(a[i], b[i]) + remainPowser;
        }

        System.out.println(kill);
    } main {
        init();

        long kill = 0;
        for(int i = 0; i < N; i++) {
            long remainPowser = 0;
            if(b[i] > a[i]) {
                remainPowser = Math.min(b[i] - a[i], a[i + 1]);
                if(a[i + 1] > remainPowser) {
                    a[i + 1] = a[i + 1] - remainPowser;
                } else {
                    a[i + 1] = Math.max(a[i + 1] - (b[i] - a[i]), 0);
                }
            }
            kill += Math.min(a[i], b[i]) + remainPowser;
        }

        System.out.println(kill);
    } init() init long kill = 0; kill 0 for(int i = 0; i < N; i++) {
            long remainPowser = 0;
            if(b[i] > a[i]) {
                remainPowser = Math.min(b[i] - a[i], a[i + 1]);
                if(a[i + 1] > remainPowser) {
                    a[i + 1] = a[i + 1] - remainPowser;
                } else {
                    a[i + 1] = Math.max(a[i + 1] - (b[i] - a[i]), 0);
                }
            }
            kill += Math.min(a[i], b[i]) + remainPowser;
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            long remainPowser = 0;
            if(b[i] > a[i]) {
                remainPowser = Math.min(b[i] - a[i], a[i + 1]);
                if(a[i + 1] > remainPowser) {
                    a[i + 1] = a[i + 1] - remainPowser;
                } else {
                    a[i + 1] = Math.max(a[i + 1] - (b[i] - a[i]), 0);
                }
            }
            kill += Math.min(a[i], b[i]) + remainPowser;
        } {
            long remainPowser = 0;
            if(b[i] > a[i]) {
                remainPowser = Math.min(b[i] - a[i], a[i + 1]);
                if(a[i + 1] > remainPowser) {
                    a[i + 1] = a[i + 1] - remainPowser;
                } else {
                    a[i + 1] = Math.max(a[i + 1] - (b[i] - a[i]), 0);
                }
            }
            kill += Math.min(a[i], b[i]) + remainPowser;
        } long remainPowser = 0; remainPowser 0 if(b[i] > a[i]) {
                remainPowser = Math.min(b[i] - a[i], a[i + 1]);
                if(a[i + 1] > remainPowser) {
                    a[i + 1] = a[i + 1] - remainPowser;
                } else {
                    a[i + 1] = Math.max(a[i + 1] - (b[i] - a[i]), 0);
                }
            } b[i] > a[i] b[i] b i a[i] a i {
                remainPowser = Math.min(b[i] - a[i], a[i + 1]);
                if(a[i + 1] > remainPowser) {
                    a[i + 1] = a[i + 1] - remainPowser;
                } else {
                    a[i + 1] = Math.max(a[i + 1] - (b[i] - a[i]), 0);
                }
            } remainPowser = Math.min(b[i] - a[i], a[i + 1]) remainPowser Math.min(b[i] - a[i], a[i + 1]) Math.min Math b[i] - a[i] b[i] b i a[i] a i a[i + 1] a i + 1 i 1 if(a[i + 1] > remainPowser) {
                    a[i + 1] = a[i + 1] - remainPowser;
                } else {
                    a[i + 1] = Math.max(a[i + 1] - (b[i] - a[i]), 0);
                } a[i + 1] > remainPowser a[i + 1] a i + 1 i 1 remainPowser {
                    a[i + 1] = a[i + 1] - remainPowser;
                } a[i + 1] = a[i + 1] - remainPowser a[i + 1] a i + 1 i 1 a[i + 1] - remainPowser a[i + 1] a i + 1 i 1 remainPowser {
                    a[i + 1] = Math.max(a[i + 1] - (b[i] - a[i]), 0);
                } a[i + 1] = Math.max(a[i + 1] - (b[i] - a[i]), 0) a[i + 1] a i + 1 i 1 Math.max(a[i + 1] - (b[i] - a[i]), 0) Math.max Math a[i + 1] - (b[i] - a[i]) a[i + 1] a i + 1 i 1 (b[i] - a[i]) b[i] b i a[i] a i 0 kill += Math.min(a[i], b[i]) + remainPowser kill Math.min(a[i], b[i]) + remainPowser Math.min(a[i], b[i]) Math.min Math a[i] a i b[i] b i remainPowser System.out.println(kill) System.out.println System.out System System.out kill String[] args args public class Main {
    static int N;
    static long[] a;
    static long[] b;

    private static void init() {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        a = new long[N + 1];
        b = new long[N];
        for(int i = 0; i <= N; i++) {
            a[i] = scanner.nextLong();
        }
        for(int i = 0; i < N; i++) {
            b[i] = scanner.nextLong();
        }
        scanner.close();
    }


    public static void main(String[] args) {
        init();

        long kill = 0;
        for(int i = 0; i < N; i++) {
            long remainPowser = 0;
            if(b[i] > a[i]) {
                remainPowser = Math.min(b[i] - a[i], a[i + 1]);
                if(a[i + 1] > remainPowser) {
                    a[i + 1] = a[i + 1] - remainPowser;
                } else {
                    a[i + 1] = Math.max(a[i + 1] - (b[i] - a[i]), 0);
                }
            }
            kill += Math.min(a[i], b[i]) + remainPowser;
        }

        System.out.println(kill);
    }
} public class Main {
    static int N;
    static long[] a;
    static long[] b;

    private static void init() {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        a = new long[N + 1];
        b = new long[N];
        for(int i = 0; i <= N; i++) {
            a[i] = scanner.nextLong();
        }
        for(int i = 0; i < N; i++) {
            b[i] = scanner.nextLong();
        }
        scanner.close();
    }


    public static void main(String[] args) {
        init();

        long kill = 0;
        for(int i = 0; i < N; i++) {
            long remainPowser = 0;
            if(b[i] > a[i]) {
                remainPowser = Math.min(b[i] - a[i], a[i + 1]);
                if(a[i + 1] > remainPowser) {
                    a[i + 1] = a[i + 1] - remainPowser;
                } else {
                    a[i + 1] = Math.max(a[i + 1] - (b[i] - a[i]), 0);
                }
            }
            kill += Math.min(a[i], b[i]) + remainPowser;
        }

        System.out.println(kill);
    }
} Main
import java.util.Scanner;

public class Main {
    static int N;
    static long[] a;
    static long[] b;

    private static void init() {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        a = new long[N + 1];
        b = new long[N];
        for(int i = 0; i <= N; i++) {
            a[i] = scanner.nextLong();
        }
        for(int i = 0; i < N; i++) {
            b[i] = scanner.nextLong();
        }
        scanner.close();
    }


    public static void main(String[] args) {
        init();

        long kill = 0;
        for(int i = 0; i < N; i++) {
            long remainPowser = 0;
            if(b[i] > a[i]) {
                remainPowser = Math.min(b[i] - a[i], a[i + 1]);
                if(a[i + 1] > remainPowser) {
                    a[i + 1] = a[i + 1] - remainPowser;
                } else {
                    a[i + 1] = Math.max(a[i + 1] - (b[i] - a[i]), 0);
                }
            }
            kill += Math.min(a[i], b[i]) + remainPowser;
        }

        System.out.println(kill);
    }
}