#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};
const int M = 100005 * 4;
long long a[M], b[M];
bool vis[M];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    vis[a[i]] = 1;
  }
  for (int i = 0; i < (n); i++) cin >> b[i];
  int cnt = 1, res = 0;
  for (int i = 0; i < (n); i++) {
    if (vis[cnt]) {
      cnt++;
    }
    res++;
    vis[b[i]] = 1;
  }
  res += (n - cnt + 1);
  int ress = 0;
  bool flg = 0;
  cnt = 1;
  for (int i = n - 1; i >= 0; i--) {
    if (b[i] == 1) {
      cnt = b[n - 1] + 1;
      break;
    }
    if (i > 0 && b[i] != b[i - 1] + 1) {
      flg = true;
      break;
    }
  }
  if (flg) {
    cout << res << endl;
    return 0;
  }
  memset((vis), 0, sizeof(vis));
  for (int i = 0; i < (n); i++) vis[a[i]] = 1;
  for (int i = 0; i < (n); i++) {
    if (cnt > n) {
      break;
    }
    if (vis[cnt]) {
      cnt++;
    } else {
      ress = 2134567891;
      break;
    }
    ress++;
    vis[b[i]] = 1;
  }
  ress += (n - cnt + 1);
  cout << min(res, ress) << endl;
  return 0;
}
