#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2.1e5;
const int INF = (int)1e9;
const int MOD = (int)(1e9) + 7;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> hand(n + 1);
  vector<int> deck(n + 1);
  vector<int> pos_in_deck(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> hand[i + 1];
  }
  for (int i = 0; i < n; i++) {
    cin >> deck[i + 1];
    pos_in_deck[deck[i + 1]] = i + 1;
  }
  if (pos_in_deck[1]) {
    bool can_finish_fast = true;
    for (int j = pos_in_deck[1]; j <= n; j++) {
      if (deck[j] != j - pos_in_deck[1] + 1) {
        can_finish_fast = false;
        break;
      }
    }
    if (can_finish_fast) {
      for (int j = deck[n] + 1; j <= n; j++) {
        if (pos_in_deck[j] > j - deck[n] - 1) {
          can_finish_fast = false;
          break;
        }
      }
    }
    if (can_finish_fast) {
      cout << n - deck[n] << '\n';
      exit(0);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int p = pos_in_deck[i];
    if (p > i - 1) {
      ans = max(ans, p - i + 1);
    }
  }
  ans += n;
  cout << ans << '\n';
  return 0;
}
