#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long large = 2000000000000000000LL;
int main() {
  int n;
  cin >> n;
  vector<int> a(n, 0), b(n, 0);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) scanf("%d", &b[i]);
  set<int> s;
  for (int i = 0; i < n; i++)
    if (a[i]) s.insert(a[i]);
  if ((int)s.size() == n) {
    cout << n << endl;
    return 0;
  }
  int pt = -1;
  for (int i = 0; i < n; i++)
    if (b[i] == 1) {
      pt = i;
      break;
    }
  if (pt != -1) {
    int check = 2;
    bool can = true;
    for (int j = pt + 1; j < n; j++) {
      if (b[j] != check) {
        can = false;
        break;
      }
      check++;
    }
    if (can) {
      int l = 0;
      if (s.empty()) {
        if (check == n + 1) {
          cout << 0 << endl;
          return 0;
        }
      } else {
        while (!s.empty()) {
          if (s.find(b.back() + 1) != s.end()) {
            s.erase(b.back() + 1);
            b.push_back(b.back() + 1);
            if (b[l] != 0) s.insert(b[l]);
            l++;
          } else {
            can = false;
            break;
          }
        }
        if (can) {
          cout << l << endl;
          return 0;
        } else {
          while ((int)b.size() > n) b.pop_back();
        }
      }
    }
  } else {
    int check = 1;
    bool can = true;
    int l = 0;
    while (!s.empty()) {
      if (s.find(check) != s.end()) {
        s.erase(check);
        b.push_back(check);
        if (b[l] != 0) s.insert(b[l]);
        check++;
        l++;
      } else {
        can = false;
        break;
      }
    }
    if (l != n) can = false;
    if (can) {
      cout << l << endl;
      return 0;
    } else {
      while ((int)b.size() > n) b.pop_back();
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    if (b[i]) ans = max(ans, i + 1 + 1 - b[i] + n);
  cout << ans << endl;
  return 0;
}
