#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 2;
int n, v[maxn], p[maxn], d[maxn], done, dmax;
int main() {
  int x;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    d[v[i]] = 0;
  }
  int dist = 2;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    d[p[i]] = dist - p[i];
    dist++;
  }
  int pos = -1;
  if (p[n] != 0) {
    int pos = n;
    while (p[pos] == p[pos - 1] + 1 && p[pos - 1] > 0) {
      pos--;
    }
    if (p[pos] == 1) {
      done = n - pos + 1;
    } else {
      pos = -1;
      done = 0;
    }
  }
  if (done) {
    for (int i = 1; i <= n - done; i++) {
      d[p[i]] += done;
    }
    for (int i = done + 1; i <= n; i++) {
      dmax = max(dmax, d[i]);
    }
    if (dmax == 0) {
      cout << n - done;
    } else {
      cout << n - done + n + 1;
    }
  } else {
    for (int i = 1; i <= n; i++) {
      dmax = max(dmax, d[i]);
    }
    cout << n + dmax;
  }
  return 0;
}
