#include <bits/stdc++.h>
using namespace std;
bool b[200001], bt[200001];
int a[200001];
int n;
void check_special() {
  int x = a[n - 1];
  int i = n - 1;
  while (x - 1 == a[i - 1] && x > 1) {
    x--;
    i--;
  }
  if (x != 1) return;
  for (i = 0; i <= n; i++) bt[i] = b[i];
  for (i = a[n - 1] + 1; i <= n; i++) {
    if (!bt[i]) return;
    bt[a[i - a[n - 1] - 1]] = 1;
  }
  cout << n - a[n - 1];
  exit(0);
}
bool check(int X) {
  for (int i = 0; i <= n; i++) bt[i] = b[i];
  for (int i = 0; i <= X - 1; i++) bt[a[i]] = 1;
  for (int i = 1; i <= n; i++) {
    if (!bt[i]) return 0;
    bt[a[min(X + i - 1, n - 1)]] = 1;
  }
  return 1;
}
int binSearch() {
  int L = 0, R = n;
  int res = n + 1;
  while (L <= R) {
    int Mid = (L + R) / 2;
    if (check(Mid))
      res = Mid, R = Mid - 1;
    else
      L = Mid + 1;
  }
  return res;
}
int main() {
  cin >> n;
  for (int i = 0; i <= n; i++) b[i] = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    b[x] = 1;
  }
  for (int i = 0; i < n; i++) cin >> a[i];
  check_special();
  cout << binSearch() + n;
  return 0;
}
