#include <bits/stdc++.h>
using namespace std;
const long long N = 5000 + 5, K = 501;
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n), b(n), cnt(n + 1);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]] = 0;
  }
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
    cnt[b[i]] = i + 1;
  }
  long long ans = 0, ok = 0;
  for (long long i = 0; i < n; i++) {
    if (b[i] == 1) {
      ans = i;
      ok = 1;
      for (long long j = i + 1; j < n; j++) {
        if (b[j] != b[j - 1] + 1) {
          ok = 0;
          break;
        }
      }
      break;
    }
  }
  for (long long i = b[n - 1] + 1; i <= n; i++) {
    if (cnt[i] + 1 > i - b[n - 1]) {
      ok = 0;
      break;
    }
  }
  if (ok) {
    cout << ans << endl;
    return;
  }
  for (long long i = 1; i <= n; i++) {
    ans = max(ans, cnt[i] + n - i + 1);
  }
  cout << ans << endl;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long TESTS = 1;
  while (TESTS--) {
    solve();
  }
  return 0;
}
