#include <bits/stdc++.h>
using namespace std;
long long n, k, ar[300004], b[300004];
long long dist[300004];
long long maxd;
long long pone;
bool isok() {
  for (int i = 0; i < n; i++) {
    if (b[i] != i + 1) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    if (ar[i] == 1) pone = -1;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] == 1) pone = i;
  }
  bool can = true;
  long long last = 0;
  for (int i = pone; i < n; i++) {
    if (b[i] != i - pone + 1) can = false;
    last++;
  }
  for (int i = 0; i < pone; i++) {
    if (b[i] != 0 && i >= b[i] - last - 1) maxd = 1;
  }
  if (can && maxd == 0) {
    cout << n - last << endl;
  } else {
    maxd = 0;
    for (int i = pone; i < n; i++) {
      if (b[i] != 0) maxd = max(maxd, (i - pone) - (b[i] - 1));
    }
    cout << pone + 1 + maxd + n << endl;
  }
  return 0;
}
