import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long[] array = new long[N+1];
        long[] brray = new long[N];

        for (int i=0; i<N+1; i++) {
            array[i] = scanner.nextLong();
        }
        for (int i=0; i<N; i++) {
            brray[i] = scanner.nextLong();
        }

        int aIndex = 0;
        int bIndex = 0;
        long count = 0;
        while (aIndex < N+1 && bIndex < N) {
            if (array[aIndex] <= 0) {
                aIndex++;
                continue;
            }
            if (brray[bIndex] <= 0) {
                bIndex++;
                continue;
            }

            if (aIndex - bIndex > 1) {
                bIndex++;
                continue;
            }

            if (bIndex > aIndex) {
                aIndex++;
                continue;
            }

            if (array[aIndex] > brray[bIndex]) {
                long tmpCount = brray[bIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            } else {
                long tmpCount = array[aIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            }
        }
        System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long[] array = new long[N+1];
        long[] brray = new long[N];

        for (int i=0; i<N+1; i++) {
            array[i] = scanner.nextLong();
        }
        for (int i=0; i<N; i++) {
            brray[i] = scanner.nextLong();
        }

        int aIndex = 0;
        int bIndex = 0;
        long count = 0;
        while (aIndex < N+1 && bIndex < N) {
            if (array[aIndex] <= 0) {
                aIndex++;
                continue;
            }
            if (brray[bIndex] <= 0) {
                bIndex++;
                continue;
            }

            if (aIndex - bIndex > 1) {
                bIndex++;
                continue;
            }

            if (bIndex > aIndex) {
                aIndex++;
                continue;
            }

            if (array[aIndex] > brray[bIndex]) {
                long tmpCount = brray[bIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            } else {
                long tmpCount = array[aIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            }
        }
        System.out.println(count);
    }
} Main public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long[] array = new long[N+1];
        long[] brray = new long[N];

        for (int i=0; i<N+1; i++) {
            array[i] = scanner.nextLong();
        }
        for (int i=0; i<N; i++) {
            brray[i] = scanner.nextLong();
        }

        int aIndex = 0;
        int bIndex = 0;
        long count = 0;
        while (aIndex < N+1 && bIndex < N) {
            if (array[aIndex] <= 0) {
                aIndex++;
                continue;
            }
            if (brray[bIndex] <= 0) {
                bIndex++;
                continue;
            }

            if (aIndex - bIndex > 1) {
                bIndex++;
                continue;
            }

            if (bIndex > aIndex) {
                aIndex++;
                continue;
            }

            if (array[aIndex] > brray[bIndex]) {
                long tmpCount = brray[bIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            } else {
                long tmpCount = array[aIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            }
        }
        System.out.println(count);
    } main {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long[] array = new long[N+1];
        long[] brray = new long[N];

        for (int i=0; i<N+1; i++) {
            array[i] = scanner.nextLong();
        }
        for (int i=0; i<N; i++) {
            brray[i] = scanner.nextLong();
        }

        int aIndex = 0;
        int bIndex = 0;
        long count = 0;
        while (aIndex < N+1 && bIndex < N) {
            if (array[aIndex] <= 0) {
                aIndex++;
                continue;
            }
            if (brray[bIndex] <= 0) {
                bIndex++;
                continue;
            }

            if (aIndex - bIndex > 1) {
                bIndex++;
                continue;
            }

            if (bIndex > aIndex) {
                aIndex++;
                continue;
            }

            if (array[aIndex] > brray[bIndex]) {
                long tmpCount = brray[bIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            } else {
                long tmpCount = array[aIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            }
        }
        System.out.println(count);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner long[] array = new long[N+1]; array new long[N+1] N+1 N 1 long[] brray = new long[N]; brray new long[N] N for (int i=0; i<N+1; i++) {
            array[i] = scanner.nextLong();
        } int i=0; int i=0; i 0 i<N+1 i N+1 N 1 i++ i++ i {
            array[i] = scanner.nextLong();
        } {
            array[i] = scanner.nextLong();
        } array[i] = scanner.nextLong() array[i] array i scanner.nextLong() scanner.nextLong scanner for (int i=0; i<N; i++) {
            brray[i] = scanner.nextLong();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            brray[i] = scanner.nextLong();
        } {
            brray[i] = scanner.nextLong();
        } brray[i] = scanner.nextLong() brray[i] brray i scanner.nextLong() scanner.nextLong scanner int aIndex = 0; aIndex 0 int bIndex = 0; bIndex 0 long count = 0; count 0 while (aIndex < N+1 && bIndex < N) {
            if (array[aIndex] <= 0) {
                aIndex++;
                continue;
            }
            if (brray[bIndex] <= 0) {
                bIndex++;
                continue;
            }

            if (aIndex - bIndex > 1) {
                bIndex++;
                continue;
            }

            if (bIndex > aIndex) {
                aIndex++;
                continue;
            }

            if (array[aIndex] > brray[bIndex]) {
                long tmpCount = brray[bIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            } else {
                long tmpCount = array[aIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            }
        } aIndex < N+1 && bIndex < N aIndex < N+1 aIndex N+1 N 1 bIndex < N bIndex N {
            if (array[aIndex] <= 0) {
                aIndex++;
                continue;
            }
            if (brray[bIndex] <= 0) {
                bIndex++;
                continue;
            }

            if (aIndex - bIndex > 1) {
                bIndex++;
                continue;
            }

            if (bIndex > aIndex) {
                aIndex++;
                continue;
            }

            if (array[aIndex] > brray[bIndex]) {
                long tmpCount = brray[bIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            } else {
                long tmpCount = array[aIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            }
        } if (array[aIndex] <= 0) {
                aIndex++;
                continue;
            } array[aIndex] <= 0 array[aIndex] array aIndex 0 {
                aIndex++;
                continue;
            } aIndex++ aIndex continue; if (brray[bIndex] <= 0) {
                bIndex++;
                continue;
            } brray[bIndex] <= 0 brray[bIndex] brray bIndex 0 {
                bIndex++;
                continue;
            } bIndex++ bIndex continue; if (aIndex - bIndex > 1) {
                bIndex++;
                continue;
            } aIndex - bIndex > 1 aIndex - bIndex aIndex bIndex 1 {
                bIndex++;
                continue;
            } bIndex++ bIndex continue; if (bIndex > aIndex) {
                aIndex++;
                continue;
            } bIndex > aIndex bIndex aIndex {
                aIndex++;
                continue;
            } aIndex++ aIndex continue; if (array[aIndex] > brray[bIndex]) {
                long tmpCount = brray[bIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            } else {
                long tmpCount = array[aIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            } array[aIndex] > brray[bIndex] array[aIndex] array aIndex brray[bIndex] brray bIndex {
                long tmpCount = brray[bIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            } long tmpCount = brray[bIndex]; tmpCount brray[bIndex] brray bIndex array[aIndex] -= tmpCount array[aIndex] array aIndex tmpCount brray[bIndex] -= tmpCount brray[bIndex] brray bIndex tmpCount count += tmpCount count tmpCount {
                long tmpCount = array[aIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            } long tmpCount = array[aIndex]; tmpCount array[aIndex] array aIndex array[aIndex] -= tmpCount array[aIndex] array aIndex tmpCount brray[bIndex] -= tmpCount brray[bIndex] brray bIndex tmpCount count += tmpCount count tmpCount System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long[] array = new long[N+1];
        long[] brray = new long[N];

        for (int i=0; i<N+1; i++) {
            array[i] = scanner.nextLong();
        }
        for (int i=0; i<N; i++) {
            brray[i] = scanner.nextLong();
        }

        int aIndex = 0;
        int bIndex = 0;
        long count = 0;
        while (aIndex < N+1 && bIndex < N) {
            if (array[aIndex] <= 0) {
                aIndex++;
                continue;
            }
            if (brray[bIndex] <= 0) {
                bIndex++;
                continue;
            }

            if (aIndex - bIndex > 1) {
                bIndex++;
                continue;
            }

            if (bIndex > aIndex) {
                aIndex++;
                continue;
            }

            if (array[aIndex] > brray[bIndex]) {
                long tmpCount = brray[bIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            } else {
                long tmpCount = array[aIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            }
        }
        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long[] array = new long[N+1];
        long[] brray = new long[N];

        for (int i=0; i<N+1; i++) {
            array[i] = scanner.nextLong();
        }
        for (int i=0; i<N; i++) {
            brray[i] = scanner.nextLong();
        }

        int aIndex = 0;
        int bIndex = 0;
        long count = 0;
        while (aIndex < N+1 && bIndex < N) {
            if (array[aIndex] <= 0) {
                aIndex++;
                continue;
            }
            if (brray[bIndex] <= 0) {
                bIndex++;
                continue;
            }

            if (aIndex - bIndex > 1) {
                bIndex++;
                continue;
            }

            if (bIndex > aIndex) {
                aIndex++;
                continue;
            }

            if (array[aIndex] > brray[bIndex]) {
                long tmpCount = brray[bIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            } else {
                long tmpCount = array[aIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            }
        }
        System.out.println(count);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long[] array = new long[N+1];
        long[] brray = new long[N];

        for (int i=0; i<N+1; i++) {
            array[i] = scanner.nextLong();
        }
        for (int i=0; i<N; i++) {
            brray[i] = scanner.nextLong();
        }

        int aIndex = 0;
        int bIndex = 0;
        long count = 0;
        while (aIndex < N+1 && bIndex < N) {
            if (array[aIndex] <= 0) {
                aIndex++;
                continue;
            }
            if (brray[bIndex] <= 0) {
                bIndex++;
                continue;
            }

            if (aIndex - bIndex > 1) {
                bIndex++;
                continue;
            }

            if (bIndex > aIndex) {
                aIndex++;
                continue;
            }

            if (array[aIndex] > brray[bIndex]) {
                long tmpCount = brray[bIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            } else {
                long tmpCount = array[aIndex];
                array[aIndex] -= tmpCount;
                brray[bIndex] -= tmpCount;
                count += tmpCount;
            }
        }
        System.out.println(count);
    }
}