import java.util.Scanner;
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];
   int[] b = new int[N];  
   for(int i = 0; i<N+1 ; i++){
   a[i] = sc.nextInt();
   }
   for(int i = 0; i<N ; i++){
   b[i] = sc.nextInt();
   }
   int tmpa1 = 0;
   int tmpa2 = 0;
   int tmpb1 = 0;
   long total = 0;
 for(int i=0;i<N;i++){
   if(i==0){
   tmpa1 = a[i];
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }else{
   tmpa1 = tmpa2;
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }
   if(tmpa1 >=tmpb1){
    total+=tmpb1; 
   }else{
     tmpb1 = tmpb1 - tmpa1 ;
     total+=tmpa1 ;
     if(tmpb1>=tmpa2){
      total+=tmpa2;
       tmpa2=0;
     }else{
      total +=tmpb1;
      tmpa2 -=tmpb1;
   }
   }
  }
   System.out.println(total);
 }
} import java.util.Scanner; Scanner 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];
   int[] b = new int[N];  
   for(int i = 0; i<N+1 ; i++){
   a[i] = sc.nextInt();
   }
   for(int i = 0; i<N ; i++){
   b[i] = sc.nextInt();
   }
   int tmpa1 = 0;
   int tmpa2 = 0;
   int tmpb1 = 0;
   long total = 0;
 for(int i=0;i<N;i++){
   if(i==0){
   tmpa1 = a[i];
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }else{
   tmpa1 = tmpa2;
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }
   if(tmpa1 >=tmpb1){
    total+=tmpb1; 
   }else{
     tmpb1 = tmpb1 - tmpa1 ;
     total+=tmpa1 ;
     if(tmpb1>=tmpa2){
      total+=tmpa2;
       tmpa2=0;
     }else{
      total +=tmpb1;
      tmpa2 -=tmpb1;
   }
   }
  }
   System.out.println(total);
 }
} Main public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] a = new int[N+1];
   int[] b = new int[N];  
   for(int i = 0; i<N+1 ; i++){
   a[i] = sc.nextInt();
   }
   for(int i = 0; i<N ; i++){
   b[i] = sc.nextInt();
   }
   int tmpa1 = 0;
   int tmpa2 = 0;
   int tmpb1 = 0;
   long total = 0;
 for(int i=0;i<N;i++){
   if(i==0){
   tmpa1 = a[i];
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }else{
   tmpa1 = tmpa2;
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }
   if(tmpa1 >=tmpb1){
    total+=tmpb1; 
   }else{
     tmpb1 = tmpb1 - tmpa1 ;
     total+=tmpa1 ;
     if(tmpb1>=tmpa2){
      total+=tmpa2;
       tmpa2=0;
     }else{
      total +=tmpb1;
      tmpa2 -=tmpb1;
   }
   }
  }
   System.out.println(total);
 } main {
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] a = new int[N+1];
   int[] b = new int[N];  
   for(int i = 0; i<N+1 ; i++){
   a[i] = sc.nextInt();
   }
   for(int i = 0; i<N ; i++){
   b[i] = sc.nextInt();
   }
   int tmpa1 = 0;
   int tmpa2 = 0;
   int tmpb1 = 0;
   long total = 0;
 for(int i=0;i<N;i++){
   if(i==0){
   tmpa1 = a[i];
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }else{
   tmpa1 = tmpa2;
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }
   if(tmpa1 >=tmpb1){
    total+=tmpb1; 
   }else{
     tmpb1 = tmpb1 - tmpa1 ;
     total+=tmpa1 ;
     if(tmpb1>=tmpa2){
      total+=tmpa2;
       tmpa2=0;
     }else{
      total +=tmpb1;
      tmpa2 -=tmpb1;
   }
   }
  }
   System.out.println(total);
 } 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 int[] b = new int[N]; b new int[N] N 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 for(int i = 0; i<N ; i++){
   b[i] = sc.nextInt();
   } int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
   b[i] = sc.nextInt();
   } {
   b[i] = sc.nextInt();
   } b[i] = sc.nextInt() b[i] b i sc.nextInt() sc.nextInt sc int tmpa1 = 0; tmpa1 0 int tmpa2 = 0; tmpa2 0 int tmpb1 = 0; tmpb1 0 long total = 0; total 0 for(int i=0;i<N;i++){
   if(i==0){
   tmpa1 = a[i];
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }else{
   tmpa1 = tmpa2;
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }
   if(tmpa1 >=tmpb1){
    total+=tmpb1; 
   }else{
     tmpb1 = tmpb1 - tmpa1 ;
     total+=tmpa1 ;
     if(tmpb1>=tmpa2){
      total+=tmpa2;
       tmpa2=0;
     }else{
      total +=tmpb1;
      tmpa2 -=tmpb1;
   }
   }
  } int i=0; int i=0; i 0 i<N i N i++ i++ i {
   if(i==0){
   tmpa1 = a[i];
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }else{
   tmpa1 = tmpa2;
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }
   if(tmpa1 >=tmpb1){
    total+=tmpb1; 
   }else{
     tmpb1 = tmpb1 - tmpa1 ;
     total+=tmpa1 ;
     if(tmpb1>=tmpa2){
      total+=tmpa2;
       tmpa2=0;
     }else{
      total +=tmpb1;
      tmpa2 -=tmpb1;
   }
   }
  } {
   if(i==0){
   tmpa1 = a[i];
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }else{
   tmpa1 = tmpa2;
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }
   if(tmpa1 >=tmpb1){
    total+=tmpb1; 
   }else{
     tmpb1 = tmpb1 - tmpa1 ;
     total+=tmpa1 ;
     if(tmpb1>=tmpa2){
      total+=tmpa2;
       tmpa2=0;
     }else{
      total +=tmpb1;
      tmpa2 -=tmpb1;
   }
   }
  } if(i==0){
   tmpa1 = a[i];
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }else{
   tmpa1 = tmpa2;
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   } i==0 i 0 {
   tmpa1 = a[i];
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   } tmpa1 = a[i] tmpa1 a[i] a i tmpa2 = a[i+1] tmpa2 a[i+1] a i+1 i 1 tmpb1 = b[i] tmpb1 b[i] b i {
   tmpa1 = tmpa2;
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   } tmpa1 = tmpa2 tmpa1 tmpa2 tmpa2 = a[i+1] tmpa2 a[i+1] a i+1 i 1 tmpb1 = b[i] tmpb1 b[i] b i if(tmpa1 >=tmpb1){
    total+=tmpb1; 
   }else{
     tmpb1 = tmpb1 - tmpa1 ;
     total+=tmpa1 ;
     if(tmpb1>=tmpa2){
      total+=tmpa2;
       tmpa2=0;
     }else{
      total +=tmpb1;
      tmpa2 -=tmpb1;
   }
   } tmpa1 >=tmpb1 tmpa1 tmpb1 {
    total+=tmpb1; 
   } total+=tmpb1 total tmpb1 {
     tmpb1 = tmpb1 - tmpa1 ;
     total+=tmpa1 ;
     if(tmpb1>=tmpa2){
      total+=tmpa2;
       tmpa2=0;
     }else{
      total +=tmpb1;
      tmpa2 -=tmpb1;
   }
   } tmpb1 = tmpb1 - tmpa1 tmpb1 tmpb1 - tmpa1 tmpb1 tmpa1 total+=tmpa1 total tmpa1 if(tmpb1>=tmpa2){
      total+=tmpa2;
       tmpa2=0;
     }else{
      total +=tmpb1;
      tmpa2 -=tmpb1;
   } tmpb1>=tmpa2 tmpb1 tmpa2 {
      total+=tmpa2;
       tmpa2=0;
     } total+=tmpa2 total tmpa2 tmpa2=0 tmpa2 0 {
      total +=tmpb1;
      tmpa2 -=tmpb1;
   } total +=tmpb1 total tmpb1 tmpa2 -=tmpb1 tmpa2 tmpb1 System.out.println(total) System.out.println System.out System System.out total 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];
   int[] b = new int[N];  
   for(int i = 0; i<N+1 ; i++){
   a[i] = sc.nextInt();
   }
   for(int i = 0; i<N ; i++){
   b[i] = sc.nextInt();
   }
   int tmpa1 = 0;
   int tmpa2 = 0;
   int tmpb1 = 0;
   long total = 0;
 for(int i=0;i<N;i++){
   if(i==0){
   tmpa1 = a[i];
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }else{
   tmpa1 = tmpa2;
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }
   if(tmpa1 >=tmpb1){
    total+=tmpb1; 
   }else{
     tmpb1 = tmpb1 - tmpa1 ;
     total+=tmpa1 ;
     if(tmpb1>=tmpa2){
      total+=tmpa2;
       tmpa2=0;
     }else{
      total +=tmpb1;
      tmpa2 -=tmpb1;
   }
   }
  }
   System.out.println(total);
 }
} 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];
   int[] b = new int[N];  
   for(int i = 0; i<N+1 ; i++){
   a[i] = sc.nextInt();
   }
   for(int i = 0; i<N ; i++){
   b[i] = sc.nextInt();
   }
   int tmpa1 = 0;
   int tmpa2 = 0;
   int tmpb1 = 0;
   long total = 0;
 for(int i=0;i<N;i++){
   if(i==0){
   tmpa1 = a[i];
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }else{
   tmpa1 = tmpa2;
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }
   if(tmpa1 >=tmpb1){
    total+=tmpb1; 
   }else{
     tmpb1 = tmpb1 - tmpa1 ;
     total+=tmpa1 ;
     if(tmpb1>=tmpa2){
      total+=tmpa2;
       tmpa2=0;
     }else{
      total +=tmpb1;
      tmpa2 -=tmpb1;
   }
   }
  }
   System.out.println(total);
 }
} Main
import java.util.Scanner;
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];
   int[] b = new int[N];  
   for(int i = 0; i<N+1 ; i++){
   a[i] = sc.nextInt();
   }
   for(int i = 0; i<N ; i++){
   b[i] = sc.nextInt();
   }
   int tmpa1 = 0;
   int tmpa2 = 0;
   int tmpb1 = 0;
   long total = 0;
 for(int i=0;i<N;i++){
   if(i==0){
   tmpa1 = a[i];
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }else{
   tmpa1 = tmpa2;
   tmpa2 = a[i+1];
   tmpb1 = b[i];
   }
   if(tmpa1 >=tmpb1){
    total+=tmpb1; 
   }else{
     tmpb1 = tmpb1 - tmpa1 ;
     total+=tmpa1 ;
     if(tmpb1>=tmpa2){
      total+=tmpa2;
       tmpa2=0;
     }else{
      total +=tmpb1;
      tmpa2 -=tmpb1;
   }
   }
  }
   System.out.println(total);
 }
}