#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC tsmthget("avx2")
using namespace std;
const long long one = 1;
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
const long long N = 2e5;
const long long nul = 0;
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  long long n;
  cin >> n;
  vector<long long> a(n), b(n), p(n + 1);
  for (long long &i : a) {
    cin >> i;
    p[i] = 0;
  }
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
    p[b[i]] = i + 1;
  }
  long long i, j;
  if (p[1]) {
    for (i = 2; i <= n && p[i] == p[1] + i - 1; i++)
      ;
    if (p[i - 1] == n) {
      for (j = i; j <= n && p[j] <= j - i; j++)
        ;
      if (j > n) {
        cout << n - i + 1 << endl;
        return 0;
      }
    }
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    ans = max(ans, p[i] - i + 1 + n);
  }
  cout << ans << endl;
}
