#include <bits/stdc++.h>
using namespace std;
int solve() {
  int N;
  cin >> N;
  vector<int> a(N), b(N);
  for (int i = 0; i < N; ++i) cin >> a[i];
  for (int i = 0; i < N; ++i) cin >> b[i];
  if (count(b.begin(), b.end(), 1)) {
    bool inc = true;
    for (int i = N - 1; i > -1; --i) {
      if (b[i] == 1) break;
      if (b[i - 1] + 1 != b[i]) {
        inc = false;
        break;
      }
    }
    if (inc) {
      int last = b[N - 1];
      for (int i = 0; i < N; ++i) {
        if (!b[i]) continue;
        if (b[i] == 1) return N - last;
        if (b[i] - last - 2 < i) break;
      }
    }
  }
  int res = N;
  for (int i = 0; i < N; ++i)
    if (b[i]) res = max(res, i + (N - b[i]) + 2);
  return res;
}
int main() {
  cout << solve() << endl;
  return 0;
}
