import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
        Integer towns = Integer.parseInt(sc.nextLine());
        String[] Monsters = sc.nextLine().split(" ");
        String[] Braves = sc.nextLine().split(" ");

        long huntCount = 0;
        for (int i = 0; i < towns; i++) {
            int firstMonsters = Integer.parseInt(Monsters[i]);
            int bravePower = Integer.parseInt(Braves[i]);

            if (firstMonsters <= bravePower) {
                // 1つ目の町は全滅できる
                huntCount += firstMonsters;

                int secondMonsters = Integer.parseInt(Monsters[i + 1]);
                int remainBravePower = bravePower - firstMonsters;
                if (remainBravePower >= secondMonsters) {
                    // 2個目の町も全滅できる
                    huntCount += secondMonsters;
                    Monsters[i + 1] = String.valueOf(0);
                } else {

                    // ちょっと残る
                    huntCount += remainBravePower;
                    Monsters[i + 1] = String.valueOf(secondMonsters - remainBravePower);
                }
            } else {

                // 1個目の町も全滅できないが何匹かは倒せる
                huntCount += bravePower;
            }
            System.err.println(huntCount);
        }

        System.err.println();
        System.out.println(huntCount);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
        Integer towns = Integer.parseInt(sc.nextLine());
        String[] Monsters = sc.nextLine().split(" ");
        String[] Braves = sc.nextLine().split(" ");

        long huntCount = 0;
        for (int i = 0; i < towns; i++) {
            int firstMonsters = Integer.parseInt(Monsters[i]);
            int bravePower = Integer.parseInt(Braves[i]);

            if (firstMonsters <= bravePower) {
                // 1つ目の町は全滅できる
                huntCount += firstMonsters;

                int secondMonsters = Integer.parseInt(Monsters[i + 1]);
                int remainBravePower = bravePower - firstMonsters;
                if (remainBravePower >= secondMonsters) {
                    // 2個目の町も全滅できる
                    huntCount += secondMonsters;
                    Monsters[i + 1] = String.valueOf(0);
                } else {

                    // ちょっと残る
                    huntCount += remainBravePower;
                    Monsters[i + 1] = String.valueOf(secondMonsters - remainBravePower);
                }
            } else {

                // 1個目の町も全滅できないが何匹かは倒せる
                huntCount += bravePower;
            }
            System.err.println(huntCount);
        }

        System.err.println();
        System.out.println(huntCount);
    }
} Main public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
        Integer towns = Integer.parseInt(sc.nextLine());
        String[] Monsters = sc.nextLine().split(" ");
        String[] Braves = sc.nextLine().split(" ");

        long huntCount = 0;
        for (int i = 0; i < towns; i++) {
            int firstMonsters = Integer.parseInt(Monsters[i]);
            int bravePower = Integer.parseInt(Braves[i]);

            if (firstMonsters <= bravePower) {
                // 1つ目の町は全滅できる
                huntCount += firstMonsters;

                int secondMonsters = Integer.parseInt(Monsters[i + 1]);
                int remainBravePower = bravePower - firstMonsters;
                if (remainBravePower >= secondMonsters) {
                    // 2個目の町も全滅できる
                    huntCount += secondMonsters;
                    Monsters[i + 1] = String.valueOf(0);
                } else {

                    // ちょっと残る
                    huntCount += remainBravePower;
                    Monsters[i + 1] = String.valueOf(secondMonsters - remainBravePower);
                }
            } else {

                // 1個目の町も全滅できないが何匹かは倒せる
                huntCount += bravePower;
            }
            System.err.println(huntCount);
        }

        System.err.println();
        System.out.println(huntCount);
    } main {
      
        Scanner sc = new Scanner(System.in);
        Integer towns = Integer.parseInt(sc.nextLine());
        String[] Monsters = sc.nextLine().split(" ");
        String[] Braves = sc.nextLine().split(" ");

        long huntCount = 0;
        for (int i = 0; i < towns; i++) {
            int firstMonsters = Integer.parseInt(Monsters[i]);
            int bravePower = Integer.parseInt(Braves[i]);

            if (firstMonsters <= bravePower) {
                // 1つ目の町は全滅できる
                huntCount += firstMonsters;

                int secondMonsters = Integer.parseInt(Monsters[i + 1]);
                int remainBravePower = bravePower - firstMonsters;
                if (remainBravePower >= secondMonsters) {
                    // 2個目の町も全滅できる
                    huntCount += secondMonsters;
                    Monsters[i + 1] = String.valueOf(0);
                } else {

                    // ちょっと残る
                    huntCount += remainBravePower;
                    Monsters[i + 1] = String.valueOf(secondMonsters - remainBravePower);
                }
            } else {

                // 1個目の町も全滅できないが何匹かは倒せる
                huntCount += bravePower;
            }
            System.err.println(huntCount);
        }

        System.err.println();
        System.out.println(huntCount);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Integer towns = Integer.parseInt(sc.nextLine()); towns Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc String[] Monsters = sc.nextLine().split(" "); Monsters sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " String[] Braves = sc.nextLine().split(" "); Braves sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " long huntCount = 0; huntCount 0 for (int i = 0; i < towns; i++) {
            int firstMonsters = Integer.parseInt(Monsters[i]);
            int bravePower = Integer.parseInt(Braves[i]);

            if (firstMonsters <= bravePower) {
                // 1つ目の町は全滅できる
                huntCount += firstMonsters;

                int secondMonsters = Integer.parseInt(Monsters[i + 1]);
                int remainBravePower = bravePower - firstMonsters;
                if (remainBravePower >= secondMonsters) {
                    // 2個目の町も全滅できる
                    huntCount += secondMonsters;
                    Monsters[i + 1] = String.valueOf(0);
                } else {

                    // ちょっと残る
                    huntCount += remainBravePower;
                    Monsters[i + 1] = String.valueOf(secondMonsters - remainBravePower);
                }
            } else {

                // 1個目の町も全滅できないが何匹かは倒せる
                huntCount += bravePower;
            }
            System.err.println(huntCount);
        } int i = 0; int i = 0; i 0 i < towns i towns i++ i++ i {
            int firstMonsters = Integer.parseInt(Monsters[i]);
            int bravePower = Integer.parseInt(Braves[i]);

            if (firstMonsters <= bravePower) {
                // 1つ目の町は全滅できる
                huntCount += firstMonsters;

                int secondMonsters = Integer.parseInt(Monsters[i + 1]);
                int remainBravePower = bravePower - firstMonsters;
                if (remainBravePower >= secondMonsters) {
                    // 2個目の町も全滅できる
                    huntCount += secondMonsters;
                    Monsters[i + 1] = String.valueOf(0);
                } else {

                    // ちょっと残る
                    huntCount += remainBravePower;
                    Monsters[i + 1] = String.valueOf(secondMonsters - remainBravePower);
                }
            } else {

                // 1個目の町も全滅できないが何匹かは倒せる
                huntCount += bravePower;
            }
            System.err.println(huntCount);
        } {
            int firstMonsters = Integer.parseInt(Monsters[i]);
            int bravePower = Integer.parseInt(Braves[i]);

            if (firstMonsters <= bravePower) {
                // 1つ目の町は全滅できる
                huntCount += firstMonsters;

                int secondMonsters = Integer.parseInt(Monsters[i + 1]);
                int remainBravePower = bravePower - firstMonsters;
                if (remainBravePower >= secondMonsters) {
                    // 2個目の町も全滅できる
                    huntCount += secondMonsters;
                    Monsters[i + 1] = String.valueOf(0);
                } else {

                    // ちょっと残る
                    huntCount += remainBravePower;
                    Monsters[i + 1] = String.valueOf(secondMonsters - remainBravePower);
                }
            } else {

                // 1個目の町も全滅できないが何匹かは倒せる
                huntCount += bravePower;
            }
            System.err.println(huntCount);
        } int firstMonsters = Integer.parseInt(Monsters[i]); firstMonsters Integer.parseInt(Monsters[i]) Integer.parseInt Integer Monsters[i] Monsters i int bravePower = Integer.parseInt(Braves[i]); bravePower Integer.parseInt(Braves[i]) Integer.parseInt Integer Braves[i] Braves i if (firstMonsters <= bravePower) {
                // 1つ目の町は全滅できる
                huntCount += firstMonsters;

                int secondMonsters = Integer.parseInt(Monsters[i + 1]);
                int remainBravePower = bravePower - firstMonsters;
                if (remainBravePower >= secondMonsters) {
                    // 2個目の町も全滅できる
                    huntCount += secondMonsters;
                    Monsters[i + 1] = String.valueOf(0);
                } else {

                    // ちょっと残る
                    huntCount += remainBravePower;
                    Monsters[i + 1] = String.valueOf(secondMonsters - remainBravePower);
                }
            } else {

                // 1個目の町も全滅できないが何匹かは倒せる
                huntCount += bravePower;
            } firstMonsters <= bravePower firstMonsters bravePower {
                // 1つ目の町は全滅できる
                huntCount += firstMonsters;

                int secondMonsters = Integer.parseInt(Monsters[i + 1]);
                int remainBravePower = bravePower - firstMonsters;
                if (remainBravePower >= secondMonsters) {
                    // 2個目の町も全滅できる
                    huntCount += secondMonsters;
                    Monsters[i + 1] = String.valueOf(0);
                } else {

                    // ちょっと残る
                    huntCount += remainBravePower;
                    Monsters[i + 1] = String.valueOf(secondMonsters - remainBravePower);
                }
            } huntCount += firstMonsters huntCount firstMonsters int secondMonsters = Integer.parseInt(Monsters[i + 1]); secondMonsters Integer.parseInt(Monsters[i + 1]) Integer.parseInt Integer Monsters[i + 1] Monsters i + 1 i 1 int remainBravePower = bravePower - firstMonsters; remainBravePower bravePower - firstMonsters bravePower firstMonsters if (remainBravePower >= secondMonsters) {
                    // 2個目の町も全滅できる
                    huntCount += secondMonsters;
                    Monsters[i + 1] = String.valueOf(0);
                } else {

                    // ちょっと残る
                    huntCount += remainBravePower;
                    Monsters[i + 1] = String.valueOf(secondMonsters - remainBravePower);
                } remainBravePower >= secondMonsters remainBravePower secondMonsters {
                    // 2個目の町も全滅できる
                    huntCount += secondMonsters;
                    Monsters[i + 1] = String.valueOf(0);
                } huntCount += secondMonsters huntCount secondMonsters Monsters[i + 1] = String.valueOf(0) Monsters[i + 1] Monsters i + 1 i 1 String.valueOf(0) String.valueOf String 0 {

                    // ちょっと残る
                    huntCount += remainBravePower;
                    Monsters[i + 1] = String.valueOf(secondMonsters - remainBravePower);
                } huntCount += remainBravePower huntCount remainBravePower Monsters[i + 1] = String.valueOf(secondMonsters - remainBravePower) Monsters[i + 1] Monsters i + 1 i 1 String.valueOf(secondMonsters - remainBravePower) String.valueOf String secondMonsters - remainBravePower secondMonsters remainBravePower {

                // 1個目の町も全滅できないが何匹かは倒せる
                huntCount += bravePower;
            } huntCount += bravePower huntCount bravePower System.err.println(huntCount) System.err.println System.err System System.err huntCount System.err.println() System.err.println System.err System System.err System.out.println(huntCount) System.out.println System.out System System.out huntCount String[] args args public class Main {

    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
        Integer towns = Integer.parseInt(sc.nextLine());
        String[] Monsters = sc.nextLine().split(" ");
        String[] Braves = sc.nextLine().split(" ");

        long huntCount = 0;
        for (int i = 0; i < towns; i++) {
            int firstMonsters = Integer.parseInt(Monsters[i]);
            int bravePower = Integer.parseInt(Braves[i]);

            if (firstMonsters <= bravePower) {
                // 1つ目の町は全滅できる
                huntCount += firstMonsters;

                int secondMonsters = Integer.parseInt(Monsters[i + 1]);
                int remainBravePower = bravePower - firstMonsters;
                if (remainBravePower >= secondMonsters) {
                    // 2個目の町も全滅できる
                    huntCount += secondMonsters;
                    Monsters[i + 1] = String.valueOf(0);
                } else {

                    // ちょっと残る
                    huntCount += remainBravePower;
                    Monsters[i + 1] = String.valueOf(secondMonsters - remainBravePower);
                }
            } else {

                // 1個目の町も全滅できないが何匹かは倒せる
                huntCount += bravePower;
            }
            System.err.println(huntCount);
        }

        System.err.println();
        System.out.println(huntCount);
    }
} public class Main {

    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
        Integer towns = Integer.parseInt(sc.nextLine());
        String[] Monsters = sc.nextLine().split(" ");
        String[] Braves = sc.nextLine().split(" ");

        long huntCount = 0;
        for (int i = 0; i < towns; i++) {
            int firstMonsters = Integer.parseInt(Monsters[i]);
            int bravePower = Integer.parseInt(Braves[i]);

            if (firstMonsters <= bravePower) {
                // 1つ目の町は全滅できる
                huntCount += firstMonsters;

                int secondMonsters = Integer.parseInt(Monsters[i + 1]);
                int remainBravePower = bravePower - firstMonsters;
                if (remainBravePower >= secondMonsters) {
                    // 2個目の町も全滅できる
                    huntCount += secondMonsters;
                    Monsters[i + 1] = String.valueOf(0);
                } else {

                    // ちょっと残る
                    huntCount += remainBravePower;
                    Monsters[i + 1] = String.valueOf(secondMonsters - remainBravePower);
                }
            } else {

                // 1個目の町も全滅できないが何匹かは倒せる
                huntCount += bravePower;
            }
            System.err.println(huntCount);
        }

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

public class Main {

    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
        Integer towns = Integer.parseInt(sc.nextLine());
        String[] Monsters = sc.nextLine().split(" ");
        String[] Braves = sc.nextLine().split(" ");

        long huntCount = 0;
        for (int i = 0; i < towns; i++) {
            int firstMonsters = Integer.parseInt(Monsters[i]);
            int bravePower = Integer.parseInt(Braves[i]);

            if (firstMonsters <= bravePower) {
                // 1つ目の町は全滅できる
                huntCount += firstMonsters;

                int secondMonsters = Integer.parseInt(Monsters[i + 1]);
                int remainBravePower = bravePower - firstMonsters;
                if (remainBravePower >= secondMonsters) {
                    // 2個目の町も全滅できる
                    huntCount += secondMonsters;
                    Monsters[i + 1] = String.valueOf(0);
                } else {

                    // ちょっと残る
                    huntCount += remainBravePower;
                    Monsters[i + 1] = String.valueOf(secondMonsters - remainBravePower);
                }
            } else {

                // 1個目の町も全滅できないが何匹かは倒せる
                huntCount += bravePower;
            }
            System.err.println(huntCount);
        }

        System.err.println();
        System.out.println(huntCount);
    }
}
