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[] B = new Long[N];

        for(int i=0; i<=N; i++){
            A[i] = sc.nextLong();
        }

        for(int i=0; i<N; i++){
            B[i] = sc.nextLong();
        }

        Long count = 0L;
        for(int i=0; i<N; i++){
            Long current = A[i];
            Long next = A[i+1];
            if(current <= B[i]){
                B[i] -= current;
                A[i] = 0L;
            }else{
                A[i] -= B[i];
                B[i] = 0L;
            }

            if(B[i] > 0){
                if(next <= B[i]){
                    B[i] -= next;
                    A[i+1] = 0L;
                }else{
                    A[i+1] -= B[i];
                    B[i] = 0L;
                }
            }

            count += current - A[i] + next - A[i+1];
        }

        println(count);
    }

    static void println(Object o){
        System.out.println(o);
    }
    static void print(Object o){
        System.out.print(o);
    }
} 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[] B = new Long[N];

        for(int i=0; i<=N; i++){
            A[i] = sc.nextLong();
        }

        for(int i=0; i<N; i++){
            B[i] = sc.nextLong();
        }

        Long count = 0L;
        for(int i=0; i<N; i++){
            Long current = A[i];
            Long next = A[i+1];
            if(current <= B[i]){
                B[i] -= current;
                A[i] = 0L;
            }else{
                A[i] -= B[i];
                B[i] = 0L;
            }

            if(B[i] > 0){
                if(next <= B[i]){
                    B[i] -= next;
                    A[i+1] = 0L;
                }else{
                    A[i+1] -= B[i];
                    B[i] = 0L;
                }
            }

            count += current - A[i] + next - A[i+1];
        }

        println(count);
    }

    static void println(Object o){
        System.out.println(o);
    }
    static void print(Object o){
        System.out.print(o);
    }
} Main public static void main(String[] args){
        Scanner sc  = new Scanner(System.in);

        int N = sc.nextInt();

        Long[] A = new Long[N+1];
        Long[] B = new Long[N];

        for(int i=0; i<=N; i++){
            A[i] = sc.nextLong();
        }

        for(int i=0; i<N; i++){
            B[i] = sc.nextLong();
        }

        Long count = 0L;
        for(int i=0; i<N; i++){
            Long current = A[i];
            Long next = A[i+1];
            if(current <= B[i]){
                B[i] -= current;
                A[i] = 0L;
            }else{
                A[i] -= B[i];
                B[i] = 0L;
            }

            if(B[i] > 0){
                if(next <= B[i]){
                    B[i] -= next;
                    A[i+1] = 0L;
                }else{
                    A[i+1] -= B[i];
                    B[i] = 0L;
                }
            }

            count += current - A[i] + next - A[i+1];
        }

        println(count);
    } main {
        Scanner sc  = new Scanner(System.in);

        int N = sc.nextInt();

        Long[] A = new Long[N+1];
        Long[] B = new Long[N];

        for(int i=0; i<=N; i++){
            A[i] = sc.nextLong();
        }

        for(int i=0; i<N; i++){
            B[i] = sc.nextLong();
        }

        Long count = 0L;
        for(int i=0; i<N; i++){
            Long current = A[i];
            Long next = A[i+1];
            if(current <= B[i]){
                B[i] -= current;
                A[i] = 0L;
            }else{
                A[i] -= B[i];
                B[i] = 0L;
            }

            if(B[i] > 0){
                if(next <= B[i]){
                    B[i] -= next;
                    A[i+1] = 0L;
                }else{
                    A[i+1] -= B[i];
                    B[i] = 0L;
                }
            }

            count += current - A[i] + next - A[i+1];
        }

        println(count);
    } 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[] B = new Long[N]; B new Long[N] N for(int i=0; i<=N; i++){
            A[i] = sc.nextLong();
        } int i=0; int i=0; i 0 i<=N i N i++ i++ i {
            A[i] = sc.nextLong();
        } {
            A[i] = sc.nextLong();
        } A[i] = sc.nextLong() A[i] A i sc.nextLong() sc.nextLong sc for(int i=0; i<N; i++){
            B[i] = sc.nextLong();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            B[i] = sc.nextLong();
        } {
            B[i] = sc.nextLong();
        } B[i] = sc.nextLong() B[i] B i sc.nextLong() sc.nextLong sc Long count = 0L; count 0L for(int i=0; i<N; i++){
            Long current = A[i];
            Long next = A[i+1];
            if(current <= B[i]){
                B[i] -= current;
                A[i] = 0L;
            }else{
                A[i] -= B[i];
                B[i] = 0L;
            }

            if(B[i] > 0){
                if(next <= B[i]){
                    B[i] -= next;
                    A[i+1] = 0L;
                }else{
                    A[i+1] -= B[i];
                    B[i] = 0L;
                }
            }

            count += current - A[i] + next - A[i+1];
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            Long current = A[i];
            Long next = A[i+1];
            if(current <= B[i]){
                B[i] -= current;
                A[i] = 0L;
            }else{
                A[i] -= B[i];
                B[i] = 0L;
            }

            if(B[i] > 0){
                if(next <= B[i]){
                    B[i] -= next;
                    A[i+1] = 0L;
                }else{
                    A[i+1] -= B[i];
                    B[i] = 0L;
                }
            }

            count += current - A[i] + next - A[i+1];
        } {
            Long current = A[i];
            Long next = A[i+1];
            if(current <= B[i]){
                B[i] -= current;
                A[i] = 0L;
            }else{
                A[i] -= B[i];
                B[i] = 0L;
            }

            if(B[i] > 0){
                if(next <= B[i]){
                    B[i] -= next;
                    A[i+1] = 0L;
                }else{
                    A[i+1] -= B[i];
                    B[i] = 0L;
                }
            }

            count += current - A[i] + next - A[i+1];
        } Long current = A[i]; current A[i] A i Long next = A[i+1]; next A[i+1] A i+1 i 1 if(current <= B[i]){
                B[i] -= current;
                A[i] = 0L;
            }else{
                A[i] -= B[i];
                B[i] = 0L;
            } current <= B[i] current B[i] B i {
                B[i] -= current;
                A[i] = 0L;
            } B[i] -= current B[i] B i current A[i] = 0L A[i] A i 0L {
                A[i] -= B[i];
                B[i] = 0L;
            } A[i] -= B[i] A[i] A i B[i] B i B[i] = 0L B[i] B i 0L if(B[i] > 0){
                if(next <= B[i]){
                    B[i] -= next;
                    A[i+1] = 0L;
                }else{
                    A[i+1] -= B[i];
                    B[i] = 0L;
                }
            } B[i] > 0 B[i] B i 0 {
                if(next <= B[i]){
                    B[i] -= next;
                    A[i+1] = 0L;
                }else{
                    A[i+1] -= B[i];
                    B[i] = 0L;
                }
            } if(next <= B[i]){
                    B[i] -= next;
                    A[i+1] = 0L;
                }else{
                    A[i+1] -= B[i];
                    B[i] = 0L;
                } next <= B[i] next B[i] B i {
                    B[i] -= next;
                    A[i+1] = 0L;
                } B[i] -= next B[i] B i next A[i+1] = 0L A[i+1] A i+1 i 1 0L {
                    A[i+1] -= B[i];
                    B[i] = 0L;
                } A[i+1] -= B[i] A[i+1] A i+1 i 1 B[i] B i B[i] = 0L B[i] B i 0L count += current - A[i] + next - A[i+1] count current - A[i] + next - A[i+1] current - A[i] + next current - A[i] current A[i] A i next A[i+1] A i+1 i 1 println(count) println count String[] args args static void println(Object o){
        System.out.println(o);
    } println {
        System.out.println(o);
    } System.out.println(o) System.out.println System.out System System.out o Object o o static void print(Object o){
        System.out.print(o);
    } print {
        System.out.print(o);
    } System.out.print(o) System.out.print System.out System System.out o Object o o 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[] B = new Long[N];

        for(int i=0; i<=N; i++){
            A[i] = sc.nextLong();
        }

        for(int i=0; i<N; i++){
            B[i] = sc.nextLong();
        }

        Long count = 0L;
        for(int i=0; i<N; i++){
            Long current = A[i];
            Long next = A[i+1];
            if(current <= B[i]){
                B[i] -= current;
                A[i] = 0L;
            }else{
                A[i] -= B[i];
                B[i] = 0L;
            }

            if(B[i] > 0){
                if(next <= B[i]){
                    B[i] -= next;
                    A[i+1] = 0L;
                }else{
                    A[i+1] -= B[i];
                    B[i] = 0L;
                }
            }

            count += current - A[i] + next - A[i+1];
        }

        println(count);
    }

    static void println(Object o){
        System.out.println(o);
    }
    static void print(Object o){
        System.out.print(o);
    }
} 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[] B = new Long[N];

        for(int i=0; i<=N; i++){
            A[i] = sc.nextLong();
        }

        for(int i=0; i<N; i++){
            B[i] = sc.nextLong();
        }

        Long count = 0L;
        for(int i=0; i<N; i++){
            Long current = A[i];
            Long next = A[i+1];
            if(current <= B[i]){
                B[i] -= current;
                A[i] = 0L;
            }else{
                A[i] -= B[i];
                B[i] = 0L;
            }

            if(B[i] > 0){
                if(next <= B[i]){
                    B[i] -= next;
                    A[i+1] = 0L;
                }else{
                    A[i+1] -= B[i];
                    B[i] = 0L;
                }
            }

            count += current - A[i] + next - A[i+1];
        }

        println(count);
    }

    static void println(Object o){
        System.out.println(o);
    }
    static void print(Object o){
        System.out.print(o);
    }
} 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[] B = new Long[N];

        for(int i=0; i<=N; i++){
            A[i] = sc.nextLong();
        }

        for(int i=0; i<N; i++){
            B[i] = sc.nextLong();
        }

        Long count = 0L;
        for(int i=0; i<N; i++){
            Long current = A[i];
            Long next = A[i+1];
            if(current <= B[i]){
                B[i] -= current;
                A[i] = 0L;
            }else{
                A[i] -= B[i];
                B[i] = 0L;
            }

            if(B[i] > 0){
                if(next <= B[i]){
                    B[i] -= next;
                    A[i+1] = 0L;
                }else{
                    A[i+1] -= B[i];
                    B[i] = 0L;
                }
            }

            count += current - A[i] + next - A[i+1];
        }

        println(count);
    }

    static void println(Object o){
        System.out.println(o);
    }
    static void print(Object o){
        System.out.print(o);
    }
}
