#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 3e5 + 10;
int x[MAXN], y[MAXN];
int32_t main(){
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
for(int i=1; i<=n; i++) cin >> x[i];
for(int i=1; i<=n; i++) cin >> y[i];
int zero = 0, neg = 0;
int tot = 0;
for(int i=n; i>=1; i--){
tot += y[i];
int cur = min(neg, x[i]);
neg -= cur;
x[i] -= cur;
cur = min(zero, x[i]);
zero -= cur;
x[i] -= cur;
zero += min(y[i], x[i]);
y[i] = max(0LL, y[i] - x[i]);
neg += y[i];
// cout << zero << " " << neg << endl;
}
int ans = (tot - zero - neg) - neg;
cout << ans << "\n";
return 0;
}