#include <bits/stdc++.h>
using namespace std;
int n;
int bs[int(2e5 + 5)];
int main() {
  scanf("%d", &n);
  set<int> hand;
  for (int i = 0; i < n; ++i) {
    int a;
    scanf("%d", &a);
    if (a) hand.emplace(a);
  }
  for (int i = 0; i < n; ++i) scanf("%d", bs + i);
  int suflen = bs[n - 1];
  for (int i = 0; i < suflen; ++i) {
    if (bs[n - 1 - i] == suflen - i) continue;
    suflen = 0;
    break;
  }
  if (suflen) {
    bool ok = true;
    for (int i = 0, k = suflen + 1; k <= n; ++k, ++i) {
      if (hand.count(k)) {
        hand.erase(k);
        if (bs[i]) hand.emplace(bs[i]);
      } else {
        ok = false;
        break;
      }
    }
    if (ok) {
      printf("%d", n - suflen);
      return 0;
    }
  }
  int backest = 0;
  for (int i = 0; i < n; ++i) {
    if (!bs[i]) continue;
    backest = max(backest, i - bs[i] + 2);
  }
  printf("%d", n + backest);
}
