#include <bits/stdc++.h>
using namespace std;
unsigned long long n;
unsigned long long a[200005 + 5], b[200005 + 5];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int s = 0;
  int ind = -1;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] == 1) {
      ind = i;
      s = 1;
    }
  }
  int begin = 0;
  int next = 2;
  for (int i = ind + 1; i < n; i++) {
    if (b[i] == next) {
      s++;
      next++;
    } else {
      begin = 1;
      break;
    }
  }
  if (begin == 0) {
    int res = n - s;
    int s1 = s + 1;
    for (int i = 0; i < ind; i++) {
      if (b[i] == 0) {
        s1++;
        continue;
      }
      if (b[i] <= s1) {
        res = n + ind + 1;
        break;
      }
      s1++;
    }
    cout << res;
  } else {
    int res = n + ind + 1;
    int next = 2;
    int dif = 0;
    for (int i = ind + 1; i < n; i++) {
      if (b[i] == 0) {
        next++;
        continue;
      }
      if (b[i] < next) {
        if (dif < next - b[i]) dif = next - b[i];
      }
      next++;
    }
    cout << res + dif;
  }
}
