#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
const int MAXN = 1e6 + 5;
const int inf = (int)2e9 + 5;
const int infll = (int)4e18 + 5;
const int mod = (int)1e9 + 7;
void solve(){
int n;
cin >> n;
vector<int> a(n + 1), b(n + 1);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
for(int i = 1; i <= n; i++) {
cin >> b[i];
}
for(int x = 0; x <= 10; x++) {
int cur = x;
bool ok = true;
for(int i = 1; i <= n; i++) {
for(int j = i; j <= n; j++) {
if(cur >= a[j]) {
cur += b[j];
} else {
ok = false;
break;
}
}
for(int j = 1; j < i; j++) {
if(cur >= a[j]) {
cur += b[j];
} else {
ok = false;
break;
}
}
if(ok) {
cout << x << endl;
return;
}
ok = true;
cur = x;
}
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while(t--)
solve();
return 0;
}