import java.io.*;
import java.util.*;
import java.lang.Math;

public class Main {

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        long[] a = new long[n+1];
        for(int i=0;i<=n;i++) a[i] = sc.nextLong();
        long[] b = new long[n];
        for(int i=0;i<n;i++) b[i] = sc.nextLong();

        long ans = 0;

        for(int i=0;i<n;i++) {
            long take = Math.min(a[i], b[i]);
            b[i] -= take;
            long take2 = Math.min(a[i+1], b[i]);
            a[i+1] -= take2;
            ans += take + take2;
        }

        pw.println(ans);
        pw.close();
    }
} import java.io.*; io.* java import java.util.*; util.* java import java.lang.Math; Math java.lang public class Main {

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        long[] a = new long[n+1];
        for(int i=0;i<=n;i++) a[i] = sc.nextLong();
        long[] b = new long[n];
        for(int i=0;i<n;i++) b[i] = sc.nextLong();

        long ans = 0;

        for(int i=0;i<n;i++) {
            long take = Math.min(a[i], b[i]);
            b[i] -= take;
            long take2 = Math.min(a[i+1], b[i]);
            a[i+1] -= take2;
            ans += take + take2;
        }

        pw.println(ans);
        pw.close();
    }
} Main public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        long[] a = new long[n+1];
        for(int i=0;i<=n;i++) a[i] = sc.nextLong();
        long[] b = new long[n];
        for(int i=0;i<n;i++) b[i] = sc.nextLong();

        long ans = 0;

        for(int i=0;i<n;i++) {
            long take = Math.min(a[i], b[i]);
            b[i] -= take;
            long take2 = Math.min(a[i+1], b[i]);
            a[i+1] -= take2;
            ans += take + take2;
        }

        pw.println(ans);
        pw.close();
    } main {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        long[] a = new long[n+1];
        for(int i=0;i<=n;i++) a[i] = sc.nextLong();
        long[] b = new long[n];
        for(int i=0;i<n;i++) b[i] = sc.nextLong();

        long ans = 0;

        for(int i=0;i<n;i++) {
            long take = Math.min(a[i], b[i]);
            b[i] -= take;
            long take2 = Math.min(a[i+1], b[i]);
            a[i+1] -= take2;
            ans += take + take2;
        }

        pw.println(ans);
        pw.close();
    } FastScanner sc = new FastScanner(); sc new FastScanner() PrintWriter pw = new PrintWriter(System.out); pw new PrintWriter(System.out) 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 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] a i sc.nextLong() sc.nextLong sc long[] b = new long[n]; b new long[n] n 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] b i sc.nextLong() sc.nextLong sc long ans = 0; ans 0 for(int i=0;i<n;i++) {
            long take = Math.min(a[i], b[i]);
            b[i] -= take;
            long take2 = Math.min(a[i+1], b[i]);
            a[i+1] -= take2;
            ans += take + take2;
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            long take = Math.min(a[i], b[i]);
            b[i] -= take;
            long take2 = Math.min(a[i+1], b[i]);
            a[i+1] -= take2;
            ans += take + take2;
        } {
            long take = Math.min(a[i], b[i]);
            b[i] -= take;
            long take2 = Math.min(a[i+1], b[i]);
            a[i+1] -= take2;
            ans += take + take2;
        } long take = Math.min(a[i], b[i]); take Math.min(a[i], b[i]) Math.min Math a[i] a i b[i] b i b[i] -= take b[i] b i take long take2 = Math.min(a[i+1], b[i]); take2 Math.min(a[i+1], b[i]) Math.min Math a[i+1] a i+1 i 1 b[i] b i a[i+1] -= take2 a[i+1] a i+1 i 1 take2 ans += take + take2 ans take + take2 take take2 pw.println(ans) pw.println pw ans pw.close() pw.close pw String[] args args static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    } FastScanner BufferedReader br; br StringTokenizer st; st public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        } FastScanner {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        } try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();} catch (Exception e){e.printStackTrace();} Exception e {e.printStackTrace();} e.printStackTrace() e.printStackTrace e {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } br = new BufferedReader(new InputStreamReader(System.in)) br new BufferedReader(new InputStreamReader(System.in)) st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        } next {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        } if (st.hasMoreTokens()) return st.nextToken(); st.hasMoreTokens() st.hasMoreTokens st return st.nextToken(); st.nextToken() st.nextToken st try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();} Exception e {e.printStackTrace();} e.printStackTrace() e.printStackTrace e {st = new StringTokenizer(br.readLine());} st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st public int nextInt() {return Integer.parseInt(next());} nextInt {return Integer.parseInt(next());} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public long nextLong() {return Long.parseLong(next());} nextLong {return Long.parseLong(next());} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public double nextDouble() {return Double.parseDouble(next());} nextDouble {return Double.parseDouble(next());} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        } nextLine {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        } String line = ""; line "" if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();} st.hasMoreTokens() st.hasMoreTokens st line = st.nextToken() line st.nextToken() st.nextToken st try {return br.readLine();}catch(IOException e){e.printStackTrace();} catch(IOException e){e.printStackTrace();} IOException e {e.printStackTrace();} e.printStackTrace() e.printStackTrace e {return br.readLine();} return br.readLine(); br.readLine() br.readLine br while(st.hasMoreTokens()) line += " "+st.nextToken(); st.hasMoreTokens() st.hasMoreTokens st line += " "+st.nextToken() line " "+st.nextToken() " " st.nextToken() st.nextToken st return line; line public class Main {

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        long[] a = new long[n+1];
        for(int i=0;i<=n;i++) a[i] = sc.nextLong();
        long[] b = new long[n];
        for(int i=0;i<n;i++) b[i] = sc.nextLong();

        long ans = 0;

        for(int i=0;i<n;i++) {
            long take = Math.min(a[i], b[i]);
            b[i] -= take;
            long take2 = Math.min(a[i+1], b[i]);
            a[i+1] -= take2;
            ans += take + take2;
        }

        pw.println(ans);
        pw.close();
    }
} public class Main {

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        long[] a = new long[n+1];
        for(int i=0;i<=n;i++) a[i] = sc.nextLong();
        long[] b = new long[n];
        for(int i=0;i<n;i++) b[i] = sc.nextLong();

        long ans = 0;

        for(int i=0;i<n;i++) {
            long take = Math.min(a[i], b[i]);
            b[i] -= take;
            long take2 = Math.min(a[i+1], b[i]);
            a[i+1] -= take2;
            ans += take + take2;
        }

        pw.println(ans);
        pw.close();
    }
} Main
import java.io.*;
import java.util.*;
import java.lang.Math;

public class Main {

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        long[] a = new long[n+1];
        for(int i=0;i<=n;i++) a[i] = sc.nextLong();
        long[] b = new long[n];
        for(int i=0;i<n;i++) b[i] = sc.nextLong();

        long ans = 0;

        for(int i=0;i<n;i++) {
            long take = Math.min(a[i], b[i]);
            b[i] -= take;
            long take2 = Math.min(a[i+1], b[i]);
            a[i+1] -= take2;
            ans += take + take2;
        }

        pw.println(ans);
        pw.close();
    }
}
