#include <bits/stdc++.h>
using namespace std;
int N, A[200005];
bool chk[200005], chk2[200005];
vector<int> v;
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", A + i), chk[A[i]] = chk2[A[i]] = 1;
  for (int i = 1, x; i <= N; i++) scanf("%d", &x), v.push_back(x);
  int k = 0;
  for (int i = 0; i < ((int)(v).size()); i++) {
    if (v[i] == 1) {
      k = 1;
      for (int j = i + 1; j < ((int)(v).size()); j++) {
        if (v[j] == j - i + 1)
          k = j - i + 1;
        else {
          k = 0;
          break;
        }
      }
    }
  }
  int ans = 1e9;
  bool f = 0;
  for (int i = k + 1; i <= N; i++) {
    if (chk2[i]) {
      chk2[i] = 0;
      chk2[v[i - k - 1]] = 1;
    } else {
      f = 1;
      break;
    }
  }
  if (!f)
    printf("%d\n", N - k), 0;
  else {
    ans = N;
    int cnt = 0;
    for (int i = 0; i < ((int)(v).size()); i++) {
      if (v[i] == 0) continue;
      ans = max(ans, N + i + 2 - v[i]);
    }
    printf("%d\n", ans);
  }
}
