#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int P = 1000000007;
const long long mod = P;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const long double eps = 1e-8;
long long qmod(long long a, long long n, long long mod) {
  long long ans = 1;
  while (n) {
    assert(ans > 0);
    if (n & 1ll) ans = ans * a % mod;
    n >>= 1;
    a = a * a % mod;
  }
  return ans % mod;
}
int a[N << 1], b[N << 1], Left[N << 1], where[N << 1], pos[N << 1],
    rleft[N << 1];
int main() {
  ios::sync_with_stdio(false);
  int n;
  while (cin >> n) {
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) cin >> b[i];
    bool qwq = 0;
    for (int i = 1; i <= n; ++i)
      if (a[i]) qwq = 1;
    for (int i = 1; i <= n; ++i)
      if (a[i] > 0)
        Left[a[i]] = -1e9, rleft[a[i]] = -1e9, where[a[i]] = 1, pos[a[i]] = 0;
    for (int i = 1; i <= n; ++i)
      if (b[i] > 0)
        Left[b[i]] = i, rleft[b[i]] = i, where[b[i]] = 2, pos[b[i]] = i;
    if (where[1] == 2) {
      bool ok = true;
      int last = pos[1];
      for (int i = 2; i <= n; ++i) {
        if (last + 1 > n) break;
        if (last + 1 == pos[i])
          ++last;
        else {
          ok = false;
          break;
        }
      }
      if (ok) {
        for (int i = pos[1]; i <= n; ++i) rleft[b[i]] = -1e9;
        int lastcard = n - pos[1] + 1;
        bool f = 1;
        for (int i = 1; i <= n; ++i)
          if (rleft[i] - i + lastcard >= 0) f = 0;
        if (!f) {
          int ans = 0;
          for (int i = 1; i <= n; ++i)
            ans = max(ans, max(0, Left[i] - i + 1) + n);
          cerr << "case1 : ";
          cout << ans << endl;
        } else {
          int ans = 0;
          cerr << "case2 : ";
          cout << n - lastcard << endl;
        }
      } else {
        int ans = 0;
        for (int i = 1; i <= n; ++i)
          ans = max(ans, max(0, Left[i] - i + 1) + n);
        cerr << "case3 : ";
        cout << ans << endl;
      }
    } else {
      int ans = 0;
      for (int i = 1; i <= n; ++i) ans = max(ans, max(0, Left[i] - i + 1) + n);
      cerr << "case4 : ";
      cout << ans << endl;
    }
  }
  return 0;
}
