#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> hand(n), pile(n);
  for (auto &v : hand) cin >> v;
  for (auto &v : pile) cin >> v;
  int cur = -1;
  bool state = false;
  for (int i = 0; i < n; i++) {
    if (state) {
      if (pile[i] == cur + 1)
        cur++;
      else
        cur = -1;
    } else {
      if (pile[i] == 1) state = true, cur = 1;
    }
  }
  int ans = INF;
  if (~cur) {
    queue<int> q;
    cur++;
    for (auto &v : pile) q.push(v);
    set<int> ha;
    for (auto &v : hand) ha.insert(v);
    bool ok = true;
    ans = 0;
    while (cur <= n && ok) {
      if (ha.count(cur))
        ha.erase(cur), ha.insert(q.front()), q.push(cur), q.pop();
      else
        ok = false;
      cur++;
      ans++;
    }
    if (!ok) ans = INF;
  }
  int ans_2 = 0;
  for (int i = 0; i < n; i++) {
    if (pile[i] == 0) continue;
    ans_2 = max(ans_2, 2 + i - pile[i]);
  }
  cout << min(ans_2 + n, ans) << '\n';
}
