#include <bits/stdc++.h>
using namespace std;
const int sz = 2e5 + 9;
int n;
int a[sz], b[sz];
queue<int> q;
bool have[sz];
int ans, tmp;
int pos = -1;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    have[a[i]] = 1;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    q.push(b[i]);
    if (b[i] == 1) pos = i;
  }
  int curr = 1;
  bool ok = 0;
  if (pos >= 0) {
    ok = 1;
    while (pos < n && b[pos] == curr) {
      pos++;
      curr++;
    }
    if (pos != n) ok = 0;
    if (ok) {
      while (!q.empty() && curr <= n) {
        if (!have[curr]) {
          ok = 0;
          tmp = 0;
          break;
        } else {
          curr++;
          have[q.front()] = 1;
          q.pop();
          tmp++;
        }
      }
      if (ok) {
        tmp += (curr > n ? 0 : n - curr + 1);
        ans = tmp;
        tmp = 0;
      }
    }
  }
  while (!q.empty()) q.pop();
  for (int i = 0; i < n; i++) q.push(b[i]);
  curr = 1;
  while (curr <= n) {
    while (!have[curr]) {
      have[q.front()] = 1;
      q.pop();
      tmp++;
    }
    tmp++;
    curr++;
    if (q.empty()) continue;
    have[q.front()] = 1;
    q.pop();
  }
  if (ok)
    ans = min(ans, tmp);
  else
    ans = tmp;
  printf("%d", ans);
  return 0;
}
