#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, aux, p[200100], seq[200100];
  int ult = 0, tot = 0, mai = 0, pos = 0;
  bool tem[200100];
  bool entrou = 0;
  memset(tem, 0, sizeof(tem));
  memset(p, 0, sizeof(p));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &aux);
    tem[aux] = 1;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &aux);
    seq[i] = aux;
  }
  ult = n;
  for (int i = n - 1; i >= 1; i--) {
    if (seq[i] != 0 and seq[i] == seq[i + 1] - 1) {
      mai++;
      ult--;
    } else
      i = 0;
  }
  if (seq[ult] == 1) {
    mai++;
    ult--;
    p[0] = p[ult + 1] = mai;
    entrou = 1;
  } else
    mai = 0;
  for (int i = 1; i <= ult; i++) {
    tot++;
    if (mai + 1 <= n and tem[mai + 1]) {
      mai++;
    }
    tem[seq[i]] = 1;
    p[i] = mai;
    if (entrou and p[i] == p[i - 1]) {
      mai = 0;
      if (ult < n) ult++;
    }
  }
  tot += (n - mai);
  printf("%d\n", tot);
  return 0;
}
