#include <bits/stdc++.h>
using namespace std;
int n, a[200001] = {0}, b[200001] = {0}, cnt[200001] = {0};
int sol() {
  list<int> bb;
  for (int i = 0; i < n; i++) {
    bb.push_back(b[i]);
  }
  for (int i = 0; i < n; i++) {
    cnt[a[i]]++;
  }
  int ans = 0;
  while ((cnt[0] < n) && cnt[bb.back() + 1]) {
    int last = bb.back();
    cnt[last + 1]--;
    bb.push_back(last + 1);
    cnt[bb.front()]++;
    bb.pop_front();
    ans++;
  }
  int prev = 0;
  while (!bb.empty() && bb.front() == prev + 1) {
    prev++;
    bb.pop_front();
  }
  if (prev == n) return ans;
  int x = 0, y = n - 1;
  while ((y >= 0) && (b[y] != 1)) y--;
  for (int i = y + 1; i < n; i++) {
    if (b[i]) x = max(x, max(0, i - y - b[i] + 1));
  }
  return x + y + 1 + n;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  cout << sol() << "\n";
  return 0;
}
