import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N+1];
    for (int i = 0; i < N+1; i++) {
      A[i] = sc.nextInt();
    }
    long ans = 0;
    for (int i = 0; i < N; i++) {
      int b = sc.nextInt();
      if (i == 0) {
        int delL = Math.min(A[0], b);
        A[0] -= delL;
        int delR = Math.min(A[1], b-delL);
        A[1] -= delR;
        ans += (delL + delR);
      } else if (i == N-1) {
        int delR = Math.min(A[N], b);
        A[N] -= delR;
        int delL = Math.min(A[N-1], b-delR);
        A[N-1] -= delL;
        ans += (delL + delR);
      } else {
        int delL = Math.min(A[i], b);
        A[i] -= delL;
        int delR = Math.min(A[i+1], b-delL);
        A[i+1] -= delR;
        ans += (delL + delR);
      }
    }
    System.out.println(ans);
  }
} import java.util.*; util.* java public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N+1];
    for (int i = 0; i < N+1; i++) {
      A[i] = sc.nextInt();
    }
    long ans = 0;
    for (int i = 0; i < N; i++) {
      int b = sc.nextInt();
      if (i == 0) {
        int delL = Math.min(A[0], b);
        A[0] -= delL;
        int delR = Math.min(A[1], b-delL);
        A[1] -= delR;
        ans += (delL + delR);
      } else if (i == N-1) {
        int delR = Math.min(A[N], b);
        A[N] -= delR;
        int delL = Math.min(A[N-1], b-delR);
        A[N-1] -= delL;
        ans += (delL + delR);
      } else {
        int delL = Math.min(A[i], b);
        A[i] -= delL;
        int delR = Math.min(A[i+1], b-delL);
        A[i+1] -= delR;
        ans += (delL + delR);
      }
    }
    System.out.println(ans);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N+1];
    for (int i = 0; i < N+1; i++) {
      A[i] = sc.nextInt();
    }
    long ans = 0;
    for (int i = 0; i < N; i++) {
      int b = sc.nextInt();
      if (i == 0) {
        int delL = Math.min(A[0], b);
        A[0] -= delL;
        int delR = Math.min(A[1], b-delL);
        A[1] -= delR;
        ans += (delL + delR);
      } else if (i == N-1) {
        int delR = Math.min(A[N], b);
        A[N] -= delR;
        int delL = Math.min(A[N-1], b-delR);
        A[N-1] -= delL;
        ans += (delL + delR);
      } else {
        int delL = Math.min(A[i], b);
        A[i] -= delL;
        int delR = Math.min(A[i+1], b-delL);
        A[i+1] -= delR;
        ans += (delL + delR);
      }
    }
    System.out.println(ans);
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N+1];
    for (int i = 0; i < N+1; i++) {
      A[i] = sc.nextInt();
    }
    long ans = 0;
    for (int i = 0; i < N; i++) {
      int b = sc.nextInt();
      if (i == 0) {
        int delL = Math.min(A[0], b);
        A[0] -= delL;
        int delR = Math.min(A[1], b-delL);
        A[1] -= delR;
        ans += (delL + delR);
      } else if (i == N-1) {
        int delR = Math.min(A[N], b);
        A[N] -= delR;
        int delL = Math.min(A[N-1], b-delR);
        A[N-1] -= delL;
        ans += (delL + delR);
      } else {
        int delL = Math.min(A[i], b);
        A[i] -= delL;
        int delR = Math.min(A[i+1], b-delL);
        A[i+1] -= delR;
        ans += (delL + delR);
      }
    }
    System.out.println(ans);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] A = new int[N+1]; A new int[N+1] N+1 N 1 for (int i = 0; i < N+1; i++) {
      A[i] = sc.nextInt();
    } int i = 0; int i = 0; i 0 i < N+1 i N+1 N 1 i++ i++ i {
      A[i] = sc.nextInt();
    } {
      A[i] = sc.nextInt();
    } A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc long ans = 0; ans 0 for (int i = 0; i < N; i++) {
      int b = sc.nextInt();
      if (i == 0) {
        int delL = Math.min(A[0], b);
        A[0] -= delL;
        int delR = Math.min(A[1], b-delL);
        A[1] -= delR;
        ans += (delL + delR);
      } else if (i == N-1) {
        int delR = Math.min(A[N], b);
        A[N] -= delR;
        int delL = Math.min(A[N-1], b-delR);
        A[N-1] -= delL;
        ans += (delL + delR);
      } else {
        int delL = Math.min(A[i], b);
        A[i] -= delL;
        int delR = Math.min(A[i+1], b-delL);
        A[i+1] -= delR;
        ans += (delL + delR);
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      int b = sc.nextInt();
      if (i == 0) {
        int delL = Math.min(A[0], b);
        A[0] -= delL;
        int delR = Math.min(A[1], b-delL);
        A[1] -= delR;
        ans += (delL + delR);
      } else if (i == N-1) {
        int delR = Math.min(A[N], b);
        A[N] -= delR;
        int delL = Math.min(A[N-1], b-delR);
        A[N-1] -= delL;
        ans += (delL + delR);
      } else {
        int delL = Math.min(A[i], b);
        A[i] -= delL;
        int delR = Math.min(A[i+1], b-delL);
        A[i+1] -= delR;
        ans += (delL + delR);
      }
    } {
      int b = sc.nextInt();
      if (i == 0) {
        int delL = Math.min(A[0], b);
        A[0] -= delL;
        int delR = Math.min(A[1], b-delL);
        A[1] -= delR;
        ans += (delL + delR);
      } else if (i == N-1) {
        int delR = Math.min(A[N], b);
        A[N] -= delR;
        int delL = Math.min(A[N-1], b-delR);
        A[N-1] -= delL;
        ans += (delL + delR);
      } else {
        int delL = Math.min(A[i], b);
        A[i] -= delL;
        int delR = Math.min(A[i+1], b-delL);
        A[i+1] -= delR;
        ans += (delL + delR);
      }
    } int b = sc.nextInt(); b sc.nextInt() sc.nextInt sc if (i == 0) {
        int delL = Math.min(A[0], b);
        A[0] -= delL;
        int delR = Math.min(A[1], b-delL);
        A[1] -= delR;
        ans += (delL + delR);
      } else if (i == N-1) {
        int delR = Math.min(A[N], b);
        A[N] -= delR;
        int delL = Math.min(A[N-1], b-delR);
        A[N-1] -= delL;
        ans += (delL + delR);
      } else {
        int delL = Math.min(A[i], b);
        A[i] -= delL;
        int delR = Math.min(A[i+1], b-delL);
        A[i+1] -= delR;
        ans += (delL + delR);
      } i == 0 i 0 {
        int delL = Math.min(A[0], b);
        A[0] -= delL;
        int delR = Math.min(A[1], b-delL);
        A[1] -= delR;
        ans += (delL + delR);
      } int delL = Math.min(A[0], b); delL Math.min(A[0], b) Math.min Math A[0] A 0 b A[0] -= delL A[0] A 0 delL int delR = Math.min(A[1], b-delL); delR Math.min(A[1], b-delL) Math.min Math A[1] A 1 b-delL b delL A[1] -= delR A[1] A 1 delR ans += (delL + delR) ans (delL + delR) delL delR if (i == N-1) {
        int delR = Math.min(A[N], b);
        A[N] -= delR;
        int delL = Math.min(A[N-1], b-delR);
        A[N-1] -= delL;
        ans += (delL + delR);
      } else {
        int delL = Math.min(A[i], b);
        A[i] -= delL;
        int delR = Math.min(A[i+1], b-delL);
        A[i+1] -= delR;
        ans += (delL + delR);
      } i == N-1 i N-1 N 1 {
        int delR = Math.min(A[N], b);
        A[N] -= delR;
        int delL = Math.min(A[N-1], b-delR);
        A[N-1] -= delL;
        ans += (delL + delR);
      } int delR = Math.min(A[N], b); delR Math.min(A[N], b) Math.min Math A[N] A N b A[N] -= delR A[N] A N delR int delL = Math.min(A[N-1], b-delR); delL Math.min(A[N-1], b-delR) Math.min Math A[N-1] A N-1 N 1 b-delR b delR A[N-1] -= delL A[N-1] A N-1 N 1 delL ans += (delL + delR) ans (delL + delR) delL delR {
        int delL = Math.min(A[i], b);
        A[i] -= delL;
        int delR = Math.min(A[i+1], b-delL);
        A[i+1] -= delR;
        ans += (delL + delR);
      } int delL = Math.min(A[i], b); delL Math.min(A[i], b) Math.min Math A[i] A i b A[i] -= delL A[i] A i delL int delR = Math.min(A[i+1], b-delL); delR Math.min(A[i+1], b-delL) Math.min Math A[i+1] A i+1 i 1 b-delL b delL A[i+1] -= delR A[i+1] A i+1 i 1 delR ans += (delL + delR) ans (delL + delR) delL delR System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N+1];
    for (int i = 0; i < N+1; i++) {
      A[i] = sc.nextInt();
    }
    long ans = 0;
    for (int i = 0; i < N; i++) {
      int b = sc.nextInt();
      if (i == 0) {
        int delL = Math.min(A[0], b);
        A[0] -= delL;
        int delR = Math.min(A[1], b-delL);
        A[1] -= delR;
        ans += (delL + delR);
      } else if (i == N-1) {
        int delR = Math.min(A[N], b);
        A[N] -= delR;
        int delL = Math.min(A[N-1], b-delR);
        A[N-1] -= delL;
        ans += (delL + delR);
      } else {
        int delL = Math.min(A[i], b);
        A[i] -= delL;
        int delR = Math.min(A[i+1], b-delL);
        A[i+1] -= delR;
        ans += (delL + delR);
      }
    }
    System.out.println(ans);
  }
} public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N+1];
    for (int i = 0; i < N+1; i++) {
      A[i] = sc.nextInt();
    }
    long ans = 0;
    for (int i = 0; i < N; i++) {
      int b = sc.nextInt();
      if (i == 0) {
        int delL = Math.min(A[0], b);
        A[0] -= delL;
        int delR = Math.min(A[1], b-delL);
        A[1] -= delR;
        ans += (delL + delR);
      } else if (i == N-1) {
        int delR = Math.min(A[N], b);
        A[N] -= delR;
        int delL = Math.min(A[N-1], b-delR);
        A[N-1] -= delL;
        ans += (delL + delR);
      } else {
        int delL = Math.min(A[i], b);
        A[i] -= delL;
        int delR = Math.min(A[i+1], b-delL);
        A[i+1] -= delR;
        ans += (delL + delR);
      }
    }
    System.out.println(ans);
  }
} Main
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N+1];
    for (int i = 0; i < N+1; i++) {
      A[i] = sc.nextInt();
    }
    long ans = 0;
    for (int i = 0; i < N; i++) {
      int b = sc.nextInt();
      if (i == 0) {
        int delL = Math.min(A[0], b);
        A[0] -= delL;
        int delR = Math.min(A[1], b-delL);
        A[1] -= delR;
        ans += (delL + delR);
      } else if (i == N-1) {
        int delR = Math.min(A[N], b);
        A[N] -= delR;
        int delL = Math.min(A[N-1], b-delR);
        A[N-1] -= delL;
        ans += (delL + delR);
      } else {
        int delL = Math.min(A[i], b);
        A[i] -= delL;
        int delR = Math.min(A[i+1], b-delL);
        A[i+1] -= delR;
        ans += (delL + delR);
      }
    }
    System.out.println(ans);
  }
}