#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], b[n], i;
  int turns[n + 1];
  int f = 0;
  for (i = 0; i <= n; i++) turns[i] = -1;
  int pos1 = -1;
  turns[0] = -1;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    turns[a[i]] = 0;
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] == 1) pos1 = i;
    turns[b[i]] = i + 1;
  }
  int flag = 1;
  int k = 2;
  if (pos1 >= 0) {
    flag = 0;
    for (i = pos1 + 1; i < n; i++) {
      if (b[i] != k) flag = 1;
      k++;
    }
    if (flag == 0) {
      int ins = 1;
      for (i = k; i <= n; i++) {
        if ((turns[i] + 1) > ins) {
          flag = 1;
          break;
        }
        ins++;
      }
    }
  }
  if (flag == 1) {
    for (i = 1; i <= n; i++) {
      turns[i] += (n - i + 1);
    }
    sort(turns, turns + (n + 1));
    cout << turns[n];
  } else {
    cout << n - (k - 1);
  }
  return 0;
}
