#include <bits/stdc++.h>
using namespace std;
int check(vector<int> hand, vector<int> deck, int after) {
  int answer = 0;
  int n = deck.size();
  vector<char> my_cards(n + 1);
  for (int i = 0; i < hand.size(); ++i) {
    my_cards[hand[i]] = 1;
  }
  deque<int> deq;
  for (int i = 0; i < n; i++) {
    deq.push_back(deck[i]);
  }
  for (int i = 0; i < after; ++i) {
    int front = deq.front();
    deq.pop_front();
    my_cards[front] = 1;
    deq.push_back(0);
  }
  answer += after;
  int cur = 1;
  if (deq.back() != 0) {
    cur = deq.back() + 1;
  }
  answer += (n - cur + 1);
  for (int i = cur; i <= n; i++) {
    if (my_cards[i] == 0) {
      return -1;
    } else {
      int front = deq.front();
      deq.pop_front();
      my_cards[front] = 1;
      deq.push_back(i);
    }
  }
  for (int i = 0; i < n; ++i) {
    int front = deq.front();
    deq.pop_front();
    if (front != i + 1) {
      return -1;
    }
  }
  return answer;
}
int main() {
  int n;
  cin >> n;
  vector<int> hand(n), deck(n);
  for (int i = 0; i < n; ++i) {
    cin >> hand[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> deck[i];
  }
  int ans = check(hand, deck, 0);
  if (ans != -1) {
    cout << ans;
    return 0;
  }
  int l = 0, r = n;
  while (r != l) {
    int m = (r + l) / 2;
    if (check(hand, deck, m) != -1) {
      r = m;
    } else {
      l = m + 1;
    }
  }
  cout << check(hand, deck, l);
  return 0;
}
