#include <bits/stdc++.h>
using namespace std;
int n;
int* a;
int* b;
map<int, int> mp;
int br = 0;
bool moze(int k) {
  for (int i = 1; i <= n; i++) {
    if (mp[i] - k >= i) {
      return false;
    }
  }
  return true;
}
int bs(int l, int r) {
  if (l == r) {
    return l;
  } else {
    int m = (l + r) / 2;
    if (moze(m)) {
      return bs(l, m);
    } else {
      return bs(m + 1, r);
    }
  }
}
bool moguce(int k) {
  int br = 0;
  for (int i = k + 1; i <= n; i++) {
    if (mp[i] > br) {
      return false;
    }
    br++;
  }
  return true;
}
int main() {
  scanf("%d", &n);
  a = new int[n];
  b = new int[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    mp[a[i]] = 0;
  }
  int jedan = -1;
  ;
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    mp[b[i]] = i + 1;
    if (b[i] > 0) {
      br++;
    }
    if (b[i] == 1) jedan = i;
  }
  if (jedan == -1) {
    cout << bs(0, br + n) + n;
  } else {
    bool mo = true;
    for (int i = jedan + 1; i < n; i++) {
      if (b[i] != b[i - 1] + 1) {
        mo = false;
      }
    }
    if (mo == false) {
      cout << bs(0, br + n) + n;
    } else {
      int k = n - jedan;
      if (moguce(k)) {
        cout << n - k;
      } else {
        cout << bs(0, br + n) + n;
      }
    }
  }
  return 0;
}
