#include <bits/stdc++.h>
using namespace std;
long long int n;
vector<long long int> a, t;
deque<long long int> b;
long long int check() {
  auto it = find(b.begin(), b.end(), 1);
  if (it == b.end()) return -1;
  long long int ind = it - b.begin();
  long long int cnt = 1;
  while (ind < n - 1) {
    ++cnt;
    ++ind;
    if (b[ind] != b[ind - 1] + 1) return -1;
  }
  for (long long int i = cnt + 1; i <= n; ++i) {
    if (t[i] > (i - cnt - 1)) return -1;
  }
  return n - cnt;
}
signed main() {
  cin >> n;
  a.resize(n);
  b.resize(n);
  t.resize(n + 1, -1);
  long long int cnt0 = 0;
  for (long long int i = 0; i < n; ++i) {
    cin >> a[i];
    cnt0 += (a[i] == 0);
  }
  for (long long int i = 0; i < n; ++i) cin >> b[i];
  for (long long int i = 0; i < n; ++i) t[b[i]] = i + 1;
  long long int ans = check();
  if (ans != -1) {
    cout << ans << "\n";
    return 0;
  }
  long long int maxEl = 0;
  for (long long int i = 1; i <= n; ++i) maxEl = max(maxEl, t[i] - i + 1);
  ans = 0;
  while (cnt0 > 0 && maxEl > 0) {
    --cnt0;
    --maxEl;
    ++ans;
    long long int el = b.front();
    b.pop_front();
    if (el == 0) ++cnt0;
  }
  cout << ans + n << "\n";
  return 0;
}
