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+1];
    long C[] = new long[N+1];
    long D[] = new long[N+1];
    for(int i=0;i<N+1;i++){
      A[i] =sc.nextLong();}
    B[0]=sc.nextLong();
    C[0]=Math.max(B[0]-A[0],0);
    if(C[0]==0){D[0]=B[0];}
    else{D[0]=A[0];}
    for(int j=1;j<N+1;j++){
     if(j==N){B[j]=0;}
      else{B[j] =sc.nextLong();}
      if(C[j-1]<A[j]){
      C[j]=Math.max(B[j]-A[j]+C[j-1],0);}
      else{C[j]=B[j];}
      if(C[j]==0){if((j==N)&&(A[j]<C[j-1])){D[j]=D[j-1]+A[j];}else{
        D[j]=D[j-1]+C[j-1]+B[j];}}
      else{D[j]=D[j-1]+A[j];}}
    System.out.println(D[N]);
  }
} 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+1];
    long C[] = new long[N+1];
    long D[] = new long[N+1];
    for(int i=0;i<N+1;i++){
      A[i] =sc.nextLong();}
    B[0]=sc.nextLong();
    C[0]=Math.max(B[0]-A[0],0);
    if(C[0]==0){D[0]=B[0];}
    else{D[0]=A[0];}
    for(int j=1;j<N+1;j++){
     if(j==N){B[j]=0;}
      else{B[j] =sc.nextLong();}
      if(C[j-1]<A[j]){
      C[j]=Math.max(B[j]-A[j]+C[j-1],0);}
      else{C[j]=B[j];}
      if(C[j]==0){if((j==N)&&(A[j]<C[j-1])){D[j]=D[j-1]+A[j];}else{
        D[j]=D[j-1]+C[j-1]+B[j];}}
      else{D[j]=D[j-1]+A[j];}}
    System.out.println(D[N]);
  }
} 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+1];
    long C[] = new long[N+1];
    long D[] = new long[N+1];
    for(int i=0;i<N+1;i++){
      A[i] =sc.nextLong();}
    B[0]=sc.nextLong();
    C[0]=Math.max(B[0]-A[0],0);
    if(C[0]==0){D[0]=B[0];}
    else{D[0]=A[0];}
    for(int j=1;j<N+1;j++){
     if(j==N){B[j]=0;}
      else{B[j] =sc.nextLong();}
      if(C[j-1]<A[j]){
      C[j]=Math.max(B[j]-A[j]+C[j-1],0);}
      else{C[j]=B[j];}
      if(C[j]==0){if((j==N)&&(A[j]<C[j-1])){D[j]=D[j-1]+A[j];}else{
        D[j]=D[j-1]+C[j-1]+B[j];}}
      else{D[j]=D[j-1]+A[j];}}
    System.out.println(D[N]);
  } main {
    Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    long A[] = new long[N+1];
    long B[] = new long[N+1];
    long C[] = new long[N+1];
    long D[] = new long[N+1];
    for(int i=0;i<N+1;i++){
      A[i] =sc.nextLong();}
    B[0]=sc.nextLong();
    C[0]=Math.max(B[0]-A[0],0);
    if(C[0]==0){D[0]=B[0];}
    else{D[0]=A[0];}
    for(int j=1;j<N+1;j++){
     if(j==N){B[j]=0;}
      else{B[j] =sc.nextLong();}
      if(C[j-1]<A[j]){
      C[j]=Math.max(B[j]-A[j]+C[j-1],0);}
      else{C[j]=B[j];}
      if(C[j]==0){if((j==N)&&(A[j]<C[j-1])){D[j]=D[j-1]+A[j];}else{
        D[j]=D[j-1]+C[j-1]+B[j];}}
      else{D[j]=D[j-1]+A[j];}}
    System.out.println(D[N]);
  } 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+1]; B new long[N+1] N+1 N 1 long C[] = new long[N+1]; C new long[N+1] N+1 N 1 long D[] = new long[N+1]; D new long[N+1] N+1 N 1 for(int i=0;i<N+1;i++){
      A[i] =sc.nextLong();} int i=0; int i=0; i 0 i<N+1 i N+1 N 1 i++ i++ i {
      A[i] =sc.nextLong();} {
      A[i] =sc.nextLong();} A[i] =sc.nextLong() A[i] A i sc.nextLong() sc.nextLong sc B[0]=sc.nextLong() B[0] B 0 sc.nextLong() sc.nextLong sc C[0]=Math.max(B[0]-A[0],0) C[0] C 0 Math.max(B[0]-A[0],0) Math.max Math B[0]-A[0] B[0] B 0 A[0] A 0 0 if(C[0]==0){D[0]=B[0];}
    else{D[0]=A[0];} C[0]==0 C[0] C 0 0 {D[0]=B[0];} D[0]=B[0] D[0] D 0 B[0] B 0 {D[0]=A[0];} D[0]=A[0] D[0] D 0 A[0] A 0 for(int j=1;j<N+1;j++){
     if(j==N){B[j]=0;}
      else{B[j] =sc.nextLong();}
      if(C[j-1]<A[j]){
      C[j]=Math.max(B[j]-A[j]+C[j-1],0);}
      else{C[j]=B[j];}
      if(C[j]==0){if((j==N)&&(A[j]<C[j-1])){D[j]=D[j-1]+A[j];}else{
        D[j]=D[j-1]+C[j-1]+B[j];}}
      else{D[j]=D[j-1]+A[j];}} int j=1; int j=1; j 1 j<N+1 j N+1 N 1 j++ j++ j {
     if(j==N){B[j]=0;}
      else{B[j] =sc.nextLong();}
      if(C[j-1]<A[j]){
      C[j]=Math.max(B[j]-A[j]+C[j-1],0);}
      else{C[j]=B[j];}
      if(C[j]==0){if((j==N)&&(A[j]<C[j-1])){D[j]=D[j-1]+A[j];}else{
        D[j]=D[j-1]+C[j-1]+B[j];}}
      else{D[j]=D[j-1]+A[j];}} {
     if(j==N){B[j]=0;}
      else{B[j] =sc.nextLong();}
      if(C[j-1]<A[j]){
      C[j]=Math.max(B[j]-A[j]+C[j-1],0);}
      else{C[j]=B[j];}
      if(C[j]==0){if((j==N)&&(A[j]<C[j-1])){D[j]=D[j-1]+A[j];}else{
        D[j]=D[j-1]+C[j-1]+B[j];}}
      else{D[j]=D[j-1]+A[j];}} if(j==N){B[j]=0;}
      else{B[j] =sc.nextLong();} j==N j N {B[j]=0;} B[j]=0 B[j] B j 0 {B[j] =sc.nextLong();} B[j] =sc.nextLong() B[j] B j sc.nextLong() sc.nextLong sc if(C[j-1]<A[j]){
      C[j]=Math.max(B[j]-A[j]+C[j-1],0);}
      else{C[j]=B[j];} C[j-1]<A[j] C[j-1] C j-1 j 1 A[j] A j {
      C[j]=Math.max(B[j]-A[j]+C[j-1],0);} C[j]=Math.max(B[j]-A[j]+C[j-1],0) C[j] C j Math.max(B[j]-A[j]+C[j-1],0) Math.max Math B[j]-A[j]+C[j-1] B[j]-A[j] B[j] B j A[j] A j C[j-1] C j-1 j 1 0 {C[j]=B[j];} C[j]=B[j] C[j] C j B[j] B j if(C[j]==0){if((j==N)&&(A[j]<C[j-1])){D[j]=D[j-1]+A[j];}else{
        D[j]=D[j-1]+C[j-1]+B[j];}}
      else{D[j]=D[j-1]+A[j];} C[j]==0 C[j] C j 0 {if((j==N)&&(A[j]<C[j-1])){D[j]=D[j-1]+A[j];}else{
        D[j]=D[j-1]+C[j-1]+B[j];}} if((j==N)&&(A[j]<C[j-1])){D[j]=D[j-1]+A[j];}else{
        D[j]=D[j-1]+C[j-1]+B[j];} (j==N)&&(A[j]<C[j-1]) (j==N) j N (A[j]<C[j-1]) A[j] A j C[j-1] C j-1 j 1 {D[j]=D[j-1]+A[j];} D[j]=D[j-1]+A[j] D[j] D j D[j-1]+A[j] D[j-1] D j-1 j 1 A[j] A j {
        D[j]=D[j-1]+C[j-1]+B[j];} D[j]=D[j-1]+C[j-1]+B[j] D[j] D j D[j-1]+C[j-1]+B[j] D[j-1]+C[j-1]+B[j] D[j-1] D j-1 j 1 C[j-1] C j-1 j 1 B[j] B j {D[j]=D[j-1]+A[j];} D[j]=D[j-1]+A[j] D[j] D j D[j-1]+A[j] D[j-1] D j-1 j 1 A[j] A j System.out.println(D[N]) System.out.println System.out System System.out D[N] D N String[] args args 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+1];
    long C[] = new long[N+1];
    long D[] = new long[N+1];
    for(int i=0;i<N+1;i++){
      A[i] =sc.nextLong();}
    B[0]=sc.nextLong();
    C[0]=Math.max(B[0]-A[0],0);
    if(C[0]==0){D[0]=B[0];}
    else{D[0]=A[0];}
    for(int j=1;j<N+1;j++){
     if(j==N){B[j]=0;}
      else{B[j] =sc.nextLong();}
      if(C[j-1]<A[j]){
      C[j]=Math.max(B[j]-A[j]+C[j-1],0);}
      else{C[j]=B[j];}
      if(C[j]==0){if((j==N)&&(A[j]<C[j-1])){D[j]=D[j-1]+A[j];}else{
        D[j]=D[j-1]+C[j-1]+B[j];}}
      else{D[j]=D[j-1]+A[j];}}
    System.out.println(D[N]);
  }
} 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+1];
    long C[] = new long[N+1];
    long D[] = new long[N+1];
    for(int i=0;i<N+1;i++){
      A[i] =sc.nextLong();}
    B[0]=sc.nextLong();
    C[0]=Math.max(B[0]-A[0],0);
    if(C[0]==0){D[0]=B[0];}
    else{D[0]=A[0];}
    for(int j=1;j<N+1;j++){
     if(j==N){B[j]=0;}
      else{B[j] =sc.nextLong();}
      if(C[j-1]<A[j]){
      C[j]=Math.max(B[j]-A[j]+C[j-1],0);}
      else{C[j]=B[j];}
      if(C[j]==0){if((j==N)&&(A[j]<C[j-1])){D[j]=D[j-1]+A[j];}else{
        D[j]=D[j-1]+C[j-1]+B[j];}}
      else{D[j]=D[j-1]+A[j];}}
    System.out.println(D[N]);
  }
} 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+1];
    long C[] = new long[N+1];
    long D[] = new long[N+1];
    for(int i=0;i<N+1;i++){
      A[i] =sc.nextLong();}
    B[0]=sc.nextLong();
    C[0]=Math.max(B[0]-A[0],0);
    if(C[0]==0){D[0]=B[0];}
    else{D[0]=A[0];}
    for(int j=1;j<N+1;j++){
     if(j==N){B[j]=0;}
      else{B[j] =sc.nextLong();}
      if(C[j-1]<A[j]){
      C[j]=Math.max(B[j]-A[j]+C[j-1],0);}
      else{C[j]=B[j];}
      if(C[j]==0){if((j==N)&&(A[j]<C[j-1])){D[j]=D[j-1]+A[j];}else{
        D[j]=D[j-1]+C[j-1]+B[j];}}
      else{D[j]=D[j-1]+A[j];}}
    System.out.println(D[N]);
  }
}
