#include <bits/stdc++.h>
using namespace std;
bool isSolvable(long long int mid, long long int n,
                vector<long long int>& hands, vector<long long int>& pile,
                vector<long long int>& index) {
  long long int i;
  long long int c = mid;
  for (i = 1; i <= n - mid; i++) {
    if (index[i] >= c) return false;
    c++;
  }
  return true;
}
long long int solve() {
  long long int n;
  cin >> n;
  vector<long long int> hands(n);
  vector<long long int> pile(n);
  vector<long long int> index(n + 1, -1);
  for (long long int i = 0; i < n; i++) cin >> hands[i];
  for (long long int i = 0; i < n; i++) {
    cin >> pile[i];
    index[pile[i]] = i;
  }
  if (index[1] != -1) {
    long long int m = index[1];
    long long int j = 1;
    long long int i = m;
    while (i < n) {
      if (pile[i] == j) {
        i++;
        j++;
      } else
        break;
    }
    if (i == n) {
      long long int f = 0;
      long long int b;
      for (b = pile[n - 1] + 1; b <= n; b++) {
        if (index[b] >= f) break;
        f++;
      }
      if (b == n + 1) return m;
    }
  }
  long long int l = 0;
  long long int r = n;
  while (l < r) {
    int mid = (l + r) / 2;
    bool ans = isSolvable(mid, n, hands, pile, index);
    if (ans)
      r = mid;
    else
      l = mid + 1;
  }
  return n + l;
}
int main() { cout << solve() << endl; }
