#include <bits/stdc++.h>
using namespace std;
int available[200005];
int a[200005];
int b[600005];
int n;
bool boleh(int cntZero) {
  memset(available, 0, sizeof(available));
  for (int i = 0; i < n; i++) {
    available[a[i]]++;
  }
  int cnt = 0;
  for (int i = 0; i < cntZero; i++) {
    available[0]--;
    available[b[cnt]]++;
    b[n + cnt] = 0;
    cnt++;
  }
  for (int i = 1; i <= n; i++) {
    if (!available[i]) {
      return false;
    } else {
      available[i]--;
      available[b[cnt]]++;
      b[n + cnt] = i;
      cnt++;
    }
  }
  return true;
}
int main() {
  scanf("%d", &n);
  int cntZero = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    cntZero += (a[i] == 0);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  if (!cntZero) {
    printf("%d", n);
    return 0;
  }
  int cutoff = n;
  if (b[n - 1] != 0) {
    cutoff = 0;
    for (int i = n - 1; i >= 1; i--) {
      if (i - b[i] != (i - 1) - b[i - 1] || b[i - 1] == 0) {
        if (b[i] == 1) {
          cutoff = i;
        } else {
          cutoff = n;
        }
        break;
      }
    }
  }
  memset(available, 0, sizeof(available));
  available[0] = 0;
  for (int i = 0; i < n; i++) {
    available[a[i]]++;
  }
  bool successful = false;
  if (cutoff == 0) {
    successful = true;
  }
  int cnt = 0;
  for (int i = (n - cutoff + 1); i <= n; i++) {
    if (!available[i]) {
      break;
    }
    available[i]--;
    available[b[cnt]]++;
    cnt++;
    if (i == n) {
      successful = true;
    }
  }
  if (successful) {
    printf("%d\n", cutoff);
    return 0;
  }
  int lo = 0;
  int hi = n;
  while (lo < hi) {
    int mid = (lo + hi) >> 1;
    if (boleh(mid)) {
      hi = mid;
    } else {
      lo = mid + 1;
    }
  }
  printf("%d", n + lo);
  return 0;
}
