#include <bits/stdc++.h>
using namespace std;
void answer(vector<long long> &pile) {
  long long ans = pile.size(), n = pile.size();
  for (long long i = 0; i < n; i++) {
    long long pos = i + 1;
    if (pile[i] != 0) {
      ans = max(ans, pos - pile[i] + n + 1);
    }
  }
  cout << ans;
}
void solveQuestion() {
  long long n;
  cin >> n;
  vector<long long> hand(n);
  vector<long long> pile(n);
  for (long long &i : hand) {
    cin >> i;
  }
  long long oneIndex = -1;
  for (long long i = 0; i < n; i++) {
    cin >> pile[i];
    if (pile[i] == 1) {
      oneIndex = i;
    }
  }
  if (oneIndex == -1) {
    answer(pile);
    return;
  }
  bool flag = true;
  for (long long i = oneIndex + 1; i < n; i++) {
    if (pile[i] - pile[i - 1] != 1) {
      flag = false;
    }
  }
  long long required = pile.back() + 1;
  unordered_set<long long> st;
  for (long long i : hand) {
    if (i != 0) {
      st.insert(i);
    }
  }
  long long idx = 0;
  for (long long i = required; i <= n; i++) {
    if (st.count(required) == 0) {
      flag = false;
      break;
    }
    if (pile[idx] != 0) {
      st.insert(pile[idx]);
    }
    idx++;
    required++;
  }
  if (flag) {
    cout << oneIndex;
    return;
  }
  answer(pile);
}
int32_t main(int32_t argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long test = 1;
  while (test--) {
    solveQuestion();
  }
  return 0;
}
