import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    long[] A = new long[N+1];
    for (int i = 0; i <= N; i++) {
      A[i] = Integer.parseInt(sc.next());
    }

    long[] B = new long[N];
    for (int i = 0; i < N; i++) {
      B[i] = Integer.parseInt(sc.next());
    }

    long kill = 0;
    for (int i = B.length-1; i >= 0; i--) {
      kill += kill(A, B, i+1, i);
      kill += kill(A, B, i, i);
    }

    System.out.println(kill);
  }

  private static long kill(long[] A, long[] B, int ai, int bi) {
    long cnt = 0;
    long origin = A[ai];
    A[ai] = Math.max(0, A[ai]-B[bi]);      
    cnt = Math.max(0, origin-A[ai]);
    B[bi] = Math.max(0, B[bi] - cnt);    
    return cnt;
  }
} import java.util.Scanner; Scanner java.util public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    long[] A = new long[N+1];
    for (int i = 0; i <= N; i++) {
      A[i] = Integer.parseInt(sc.next());
    }

    long[] B = new long[N];
    for (int i = 0; i < N; i++) {
      B[i] = Integer.parseInt(sc.next());
    }

    long kill = 0;
    for (int i = B.length-1; i >= 0; i--) {
      kill += kill(A, B, i+1, i);
      kill += kill(A, B, i, i);
    }

    System.out.println(kill);
  }

  private static long kill(long[] A, long[] B, int ai, int bi) {
    long cnt = 0;
    long origin = A[ai];
    A[ai] = Math.max(0, A[ai]-B[bi]);      
    cnt = Math.max(0, origin-A[ai]);
    B[bi] = Math.max(0, B[bi] - cnt);    
    return cnt;
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    long[] A = new long[N+1];
    for (int i = 0; i <= N; i++) {
      A[i] = Integer.parseInt(sc.next());
    }

    long[] B = new long[N];
    for (int i = 0; i < N; i++) {
      B[i] = Integer.parseInt(sc.next());
    }

    long kill = 0;
    for (int i = B.length-1; i >= 0; i--) {
      kill += kill(A, B, i+1, i);
      kill += kill(A, B, i, i);
    }

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

    int N = Integer.parseInt(sc.next());

    long[] A = new long[N+1];
    for (int i = 0; i <= N; i++) {
      A[i] = Integer.parseInt(sc.next());
    }

    long[] B = new long[N];
    for (int i = 0; i < N; i++) {
      B[i] = Integer.parseInt(sc.next());
    }

    long kill = 0;
    for (int i = B.length-1; i >= 0; i--) {
      kill += kill(A, B, i+1, i);
      kill += kill(A, B, i, i);
    }

    System.out.println(kill);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next 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] = Integer.parseInt(sc.next());
    } int i = 0; int i = 0; i 0 i <= N i N i++ i++ i {
      A[i] = Integer.parseInt(sc.next());
    } {
      A[i] = Integer.parseInt(sc.next());
    } A[i] = Integer.parseInt(sc.next()) A[i] A i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc long[] B = new long[N]; B new long[N] N for (int i = 0; i < N; i++) {
      B[i] = Integer.parseInt(sc.next());
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      B[i] = Integer.parseInt(sc.next());
    } {
      B[i] = Integer.parseInt(sc.next());
    } B[i] = Integer.parseInt(sc.next()) B[i] B i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc long kill = 0; kill 0 for (int i = B.length-1; i >= 0; i--) {
      kill += kill(A, B, i+1, i);
      kill += kill(A, B, i, i);
    } int i = B.length-1; int i = B.length-1; i B.length-1 B.length B B.length 1 i >= 0 i 0 i-- i-- i {
      kill += kill(A, B, i+1, i);
      kill += kill(A, B, i, i);
    } {
      kill += kill(A, B, i+1, i);
      kill += kill(A, B, i, i);
    } kill += kill(A, B, i+1, i) kill kill(A, B, i+1, i) kill A B i+1 i 1 i kill += kill(A, B, i, i) kill kill(A, B, i, i) kill A B i i System.out.println(kill) System.out.println System.out System System.out kill String[] args args private static long kill(long[] A, long[] B, int ai, int bi) {
    long cnt = 0;
    long origin = A[ai];
    A[ai] = Math.max(0, A[ai]-B[bi]);      
    cnt = Math.max(0, origin-A[ai]);
    B[bi] = Math.max(0, B[bi] - cnt);    
    return cnt;
  } kill {
    long cnt = 0;
    long origin = A[ai];
    A[ai] = Math.max(0, A[ai]-B[bi]);      
    cnt = Math.max(0, origin-A[ai]);
    B[bi] = Math.max(0, B[bi] - cnt);    
    return cnt;
  } long cnt = 0; cnt 0 long origin = A[ai]; origin A[ai] A ai A[ai] = Math.max(0, A[ai]-B[bi]) A[ai] A ai Math.max(0, A[ai]-B[bi]) Math.max Math 0 A[ai]-B[bi] A[ai] A ai B[bi] B bi cnt = Math.max(0, origin-A[ai]) cnt Math.max(0, origin-A[ai]) Math.max Math 0 origin-A[ai] origin A[ai] A ai B[bi] = Math.max(0, B[bi] - cnt) B[bi] B bi Math.max(0, B[bi] - cnt) Math.max Math 0 B[bi] - cnt B[bi] B bi cnt return cnt; cnt long[] A A long[] B B int ai ai int bi bi public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    long[] A = new long[N+1];
    for (int i = 0; i <= N; i++) {
      A[i] = Integer.parseInt(sc.next());
    }

    long[] B = new long[N];
    for (int i = 0; i < N; i++) {
      B[i] = Integer.parseInt(sc.next());
    }

    long kill = 0;
    for (int i = B.length-1; i >= 0; i--) {
      kill += kill(A, B, i+1, i);
      kill += kill(A, B, i, i);
    }

    System.out.println(kill);
  }

  private static long kill(long[] A, long[] B, int ai, int bi) {
    long cnt = 0;
    long origin = A[ai];
    A[ai] = Math.max(0, A[ai]-B[bi]);      
    cnt = Math.max(0, origin-A[ai]);
    B[bi] = Math.max(0, B[bi] - cnt);    
    return cnt;
  }
} public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    long[] A = new long[N+1];
    for (int i = 0; i <= N; i++) {
      A[i] = Integer.parseInt(sc.next());
    }

    long[] B = new long[N];
    for (int i = 0; i < N; i++) {
      B[i] = Integer.parseInt(sc.next());
    }

    long kill = 0;
    for (int i = B.length-1; i >= 0; i--) {
      kill += kill(A, B, i+1, i);
      kill += kill(A, B, i, i);
    }

    System.out.println(kill);
  }

  private static long kill(long[] A, long[] B, int ai, int bi) {
    long cnt = 0;
    long origin = A[ai];
    A[ai] = Math.max(0, A[ai]-B[bi]);      
    cnt = Math.max(0, origin-A[ai]);
    B[bi] = Math.max(0, B[bi] - cnt);    
    return cnt;
  }
} Main
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    long[] A = new long[N+1];
    for (int i = 0; i <= N; i++) {
      A[i] = Integer.parseInt(sc.next());
    }

    long[] B = new long[N];
    for (int i = 0; i < N; i++) {
      B[i] = Integer.parseInt(sc.next());
    }

    long kill = 0;
    for (int i = B.length-1; i >= 0; i--) {
      kill += kill(A, B, i+1, i);
      kill += kill(A, B, i, i);
    }

    System.out.println(kill);
  }

  private static long kill(long[] A, long[] B, int ai, int bi) {
    long cnt = 0;
    long origin = A[ai];
    A[ai] = Math.max(0, A[ai]-B[bi]);      
    cnt = Math.max(0, origin-A[ai]);
    B[bi] = Math.max(0, B[bi] - cnt);    
    return cnt;
  }
}