#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<>,
rb_tree_tag, tree_order_statistics_node_update>
ordered_set;
#define ll long long
#define ii pair<ll,ll>
#define iii tuple<ll,ll,ll>
#ifndef DEBUG
#define cerr if (0) cerr
#define endl '\n'
#endif
const ll inf=1e15;
const ll maxn=3e5+5;
const ll mod=1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int arr[maxn], brr[maxn];
int good = 0, bad = 0, ok = 0;
void helper(int& x, int& y, int& z) {
int temp = min(x, y);
x -= temp;
y -= temp;
z += temp;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
for (int i = 1; i <= n; i++) {
cin >> brr[i];
}
for (int i = n; i >= 1; i--) {
//assign bad to arr[i];
//assign ok to arr[i];
//assign brr[i] to arr[i];
//assign remaining brr[i] to bad;
helper(bad, arr[i], good);
helper(ok, arr[i], good);
helper(brr[i], arr[i], ok);
bad += brr[i];
}
cout << good - bad;
return 0;
}