#include <bits/stdc++.h>
using namespace std;
const int N = 200004;
int a[N], b[N], c[N], n, t;
queue<int> q;
int ck() {
  int p;
  if (b[n] == 0) return 0;
  for (p = n; p >= 1; p--)
    if (n - b[n] != p - b[p]) break;
  if (p < n - b[n] + 1)
    return b[n] + 1;
  else
    return 0;
}
int solve() {
  memcpy(c, a, sizeof(c));
  int x = ck();
  if (x) {
    for (; x <= n; x++) {
      if (c[x] == 1) {
        int y = q.front();
        q.pop();
        c[y] = 1;
      } else
        break;
    }
    if (x > n) return n - b[n];
  }
  while (!q.empty()) q.pop();
  int p = 1;
  for (int i = 1; i <= n; i++) q.push(b[i]);
  int ans = 0;
  for (p = 1; p <= n; p++) {
    if (a[p]) {
      int y = q.front();
      q.pop();
      a[y] = 1;
      q.push(p);
    } else {
      ++ans;
      q.push(0);
      int y = q.front();
      q.pop();
      a[y] = 1;
      --p;
    }
  }
  return ans + n;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &t);
    a[t] = 1;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    q.push(b[i]);
  }
  printf("%d\n", solve());
}
