#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N], p[N], b[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  while (cin >> n) {
    for (int i = 1; i <= n; i++) cin >> a[i];
    memset(p, 0, sizeof(p));
    for (int i = 1; i <= n; i++) {
      cin >> b[i];
      if (b[i]) p[b[i]] = i;
    }
    bool f1, f2 = 1;
    int la;
    if (!p[1]) f1 = 0;
    if (p[1]) {
      f1 = 1;
      la = 1;
      for (int i = p[1] + 1; i <= n; i++) {
        if (b[i] != la + 1) {
          f1 = 0;
          break;
        } else
          la += 1;
      }
      for (int i = la + 1; i <= n; i++) {
        int ned = i - la - 1;
        if (p[i] > ned) {
          f2 = 0;
          break;
        }
      }
    }
    if (f1 && f2)
      cout << n - la << endl;
    else {
      int ma = -1e6;
      for (int i = 1; i <= n; i++) {
        int sd = i - 1;
        if (p[i] - sd > ma) {
          ma = p[i] - sd;
        }
      }
      cout << n + ma << endl;
    }
  }
  return 0;
}
