#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,a,b) for (int i = a; i >= b; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
const int MAXN = 3e5+10;
int a[MAXN], b[MAXN];
int main() {
ios_base::sync_with_stdio(0);cin.tie(nullptr);
int n; cin >> n;
set<int> x;
rep(i,1,n) cin >> a[i];
rep(i,1,n) {
cin >> b[i];
if(b[i]) x.insert(i);
}
int cnt1 = 0, cnt2 = x.size();
rep(i,1,n) {
if(!a[i]) continue;
if(x.size()==0) break;
auto it = x.upper_bound(i);
if(it!=x.end()) {
//cout << i << ' ' << *it << endl;
cnt1++;
cnt2--;
x.erase(it);
continue;
}
it--;
if(*it == i) {
cnt2--;
}
x.erase(it);
}
cout << cnt1-cnt2 << endl;
return 0;
}