//pB
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 3e5+10;
int n;
LL ans=0;
LL x[maxn], y[maxn];
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n;
for(int i=0; i<n; i++) cin>>y[i]; // 房間
for(int i=0; i<n; i++) cin>>x[i]; // 人
int yy=n-1, xx=n-1;
for(; yy>=0 and xx>=0; xx--){
if(xx==yy) yy--;
while(x[xx] and yy>=0){
LL mi = min(y[yy], x[xx]);
ans += mi;
x[xx] -= mi;
y[yy] -= mi;
if(y[yy] == 0) yy--;
}
if(x[xx]) break;
}
// cout<<xx<<" "<<yy<<"\n";
while(xx>=0){
// cout<<x[xx]<<" "<<y[xx]<<"\n";
if(y[xx]){
LL mi = min(y[xx], x[xx]);
x[xx] -= mi;
y[xx] -= mi;
}
ans -= x[xx];
xx--;
}
cout<<ans;
return 0;
}