#include <bits/stdc++.h>
using namespace std;
int n;
int have[200005], b[200005];
int have_tmp[200005];
bool check(int val, int k) {
  int cnt = 1;
  for (int i = 1; i <= n; i++) have_tmp[i] = have[i];
  int last = b[n] + 1;
  if (k == 1) {
    if (val > n) {
      val -= n;
      last = 1;
      for (; cnt <= val; cnt++) have_tmp[b[cnt]] = true;
    }
  }
  if (k == 1) val = n;
  while (val--) {
    if (!have_tmp[last]) return false;
    if (cnt <= n) {
      have_tmp[b[cnt]] = 1;
      cnt++;
    }
    last++;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    have[x] = 1;
  }
  for (int i = 1; i <= n; i++) cin >> b[i];
  int j = n + 1;
  for (int i = n; i >= 1; i--) {
    if (b[i] == 1) j = i;
    if (b[i - 1] + 1 != b[i]) break;
  }
  if (check(j - 1, 0)) return cout << j - 1, 0;
  int l = n, r = 2 * n;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid, 1))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << r + 1;
}
