#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 50;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n), b(n);
  vector<long long> p(n + 1);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] != 0) {
      p[a[i]] = 0;
    }
  }
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] != 0) {
      p[b[i]] = i + 1;
    }
  }
  {
    vector<long long> aa(n + 1);
    for (long long i = 0; i < n; i++) {
      aa[a[i]] = true;
    }
    deque<long long> bb;
    for (long long i = 0; i < n; i++) {
      bb.push_back(b[i]);
    }
    bool ok = true;
    long long ans = 0;
    while (bb.back() != n) {
      if (aa[bb.back() + 1]) {
        aa[bb.back() + 1] = false;
        bb.push_back(bb.back() + 1);
        aa[bb.front()] = true;
        bb.pop_front();
        ans++;
      } else {
        ok = false;
        break;
      }
    }
    ok &= bb.front() == 1;
    if (ok) {
      for (long long i = 1; i < n; i++) {
        ok &= (bb[i] == bb[i - 1] + 1);
      }
    }
    if (ok) {
      cout << ans << '\n';
      return 0;
    }
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    if (p[i] == 0) {
    } else {
      ans = max(ans, p[i] - i + 1 + n);
    }
  }
  cout << ans << '\n';
}
