#include <bits/stdc++.h>
using namespace std;
struct No {
  int va, id;
} pipl[200005];
int hand[200005], xu[200005];
int n, tp, ans = 0, an;
bool judge2() {
  int tx = pipl[1].id, tf = 1;
  an = tx - 1;
  int hand2[200005];
  for (int i = 1; i <= n; i++) hand2[i] = hand[i];
  for (int i = tx + 1; i <= n; i++) {
    if (xu[i] != xu[i - 1] + 1) return false;
  }
  tf = xu[n] + 1;
  int id = 1;
  while (tf <= n) {
    if (hand2[tf] == 1) {
      tf++;
      if (id < tx) hand2[xu[id]] = 1;
      id++;
    } else
      return false;
  }
  return true;
}
int main() {
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tp;
    hand[tp] = 1;
  }
  for (int i = 1; i <= n; i++) {
    cin >> xu[i];
    pipl[xu[i]].id = i;
    pipl[xu[i]].va = xu[i];
  }
  if (judge2()) {
    printf("%d\n", an);
    return 0;
  }
  for (int i = 1; i <= n; i++)
    if (hand[i] != 1) {
      ans = max(ans, pipl[i].id - (i - 1));
    }
  printf("%d\n", n + ans);
  return 0;
}
