#include <bits/stdc++.h>
using namespace std;
int n;
bool go(int x, multiset<int> &hand, deque<int> &dq) {
  if (hand.find(x) == hand.end()) return false;
  hand.erase(hand.find(x));
  hand.insert(dq.front());
  dq.pop_front();
  dq.push_back(x);
  return true;
}
multiset<int> hand;
deque<int> dq;
int Try() {
  multiset<int> hand1 = hand;
  deque<int> dq1 = dq;
  int pos = -1;
  for (int i = 0; i < n; i++) {
    if (dq[i] == 1) pos = i;
  }
  if (pos == -1) return -1;
  for (int i = pos; i < n; i++)
    if (dq[i] != i - pos + 1) return -1;
  int done = n - pos;
  int ans = 0;
  while (done < n) {
    ++done;
    ++ans;
    if (!go(done, hand1, dq1)) return -1;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    hand.insert(x);
  }
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    dq.push_back(x);
  }
  int ans = Try();
  if (ans != -1) {
    cout << ans << endl;
    return 0;
  }
  ans = 0;
  while (hand.find(1) == hand.end()) {
    assert(go(0, hand, dq));
    ans++;
  }
  int mx = n;
  for (int i = 0; i < n; i++) {
    if (dq[i] == 0) continue;
    int cur = i + 1 + (n + 1 - dq[i]);
    mx = max(mx, cur);
  }
  cout << ans + mx << endl;
}
