#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535897932384626433832;
const long long mod = 1e9 + 7;
complex<double> fast_exp(complex<double> a, long long b) {
  if (b == 0) return 1;
  complex<double> res = fast_exp(a, b / 2);
  res = res * res;
  if (b % 2 == 1) res = res * a;
  return res;
}
long long fastexpon(long long a, long long b, long long mod) {
  if (b == 0) return 1;
  long long res = fastexpon(a, b / 2, mod);
  res = (res * res) % mod;
  if (b % 2 == 1) res = (res * a) % mod;
  return res;
}
struct custom {
  bool operator()(long long a, long long b) { return a > b; }
};
int main() {
  int n, x;
  cin >> n;
  set<int> s;
  vector<int> a;
  int pos[200001];
  int setexist[200001] = {};
  for (int i = 0; i < n; i++) {
    cin >> x;
    s.insert(x);
    setexist[x] = 1;
  }
  int pos1 = -1;
  int answer = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == 1) pos1 = i;
    a.push_back(x);
    pos[x] = i;
  }
  if (pos1 == -1) {
    int maxprob = 0;
    for (int i = 2; i <= n; i++) {
      if (!setexist[i]) {
        int cur = pos[i] + 2 - i;
        maxprob = max(maxprob, cur);
      }
    }
    answer = maxprob + n;
  } else {
    int check = 1;
    for (int i = pos[1]; i < n; i++) {
      if (a[i] - 1 != i - pos[1]) {
        check = 0;
        break;
      }
    }
    int lsorted = n - 1 - pos[1] + 1;
    if (!setexist[lsorted + 1] && lsorted + 1 <= n) {
      check = 0;
    }
    for (int i = lsorted + 2; i <= n; i++) {
      if (!setexist[i]) {
        if (pos[i] > i - lsorted - 2) {
          check = 0;
        }
      }
    }
    if (check == 1) {
      answer = n - lsorted;
    } else {
      answer += pos[1] + 1;
      int prob = 0;
      for (int i = 2; i <= n; i++) {
        if (!setexist[i]) {
          int cur = pos[i] - pos[1] - (i - 1);
          prob = max(prob, cur);
        }
      }
      answer += prob;
      answer += n;
    }
  }
  cout << answer << endl;
  return 0;
}
