#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, k, A[maxn], B[maxn], ans, pos = -1, ok = 1;
bool mark[maxn];
int32_t main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    mark[A[i]] = 1;
  }
  ans = n;
  for (int i = 0; i < n; i++) {
    cin >> B[i];
    if (B[i] == 1) {
      pos = i;
    }
    if (pos != -1 && i - pos + 1 != B[i]) {
      ok = 0;
    }
    if (B[i] > 0 && B[i] <= i + 1) {
      ans = max(ans, i - B[i] + 2 + n);
    }
  }
  if (pos == -1) {
    ok = 0;
  }
  if (ok == 0) {
    cout << ans << endl;
  } else {
    for (int i = 0; i < pos; i++) {
      if (B[i] > 0) {
        if (pos + B[i] - 1 <= n + i) {
          cout << ans << endl;
          return 0;
        }
      }
    }
    cout << pos << endl;
  }
}
