#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
const long double PI =
    3.141592653589793238462643383279502884197169399375105820974944;
inline void io() {}
const long long mod = 2e15;
const long long maxn = 2e5 + 5;
long long a[maxn], b[maxn], ans;
void solve() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) cin >> b[i];
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) mp[a[i]]++;
  long long pt = 0;
  while (pt < n && b[pt] != 1) ++pt;
  if (pt < n) {
    long long ok = 1;
    for (long long i = pt; i < n - 1; i++) {
      if (b[i] + 1 != b[i + 1]) ok = 0;
    }
    if (ok) {
      long long ans = 0;
      long long cur = b[n - 1] + 1, it = 0;
      if (cur == n + 1) {
        cout << ans;
        return;
      }
      while (cur <= n) {
        if (mp[cur]) {
          ans++;
          ++cur;
          mp[b[it]]++;
          ++it;
        } else
          break;
      }
      if (cur == n + 1) {
        cout << ans;
        return;
      }
    }
  }
  long long mx = 0;
  for (long long i = 0; i < n; i++) {
    if (b[i]) mx = max(mx, i - b[i] + 2);
  }
  mx += n;
  cout << mx;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(16);
  long long tc = 1;
  while (tc--) {
    solve();
  }
  return 0;
}
