#include <bits/stdc++.h>
using namespace std;
bool calc(long long mid, long long n, long long b[]) {
  for (long long i = mid; i < n; i++) {
    if (b[i] && i - mid >= b[i] - 1) return false;
  }
  return true;
}
int main() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long b[n];
  for (long long i = 0; i < n; i++) cin >> b[i];
  long long l = 0, r = n;
  long long ans = -1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (calc(mid, n, b)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  set<long long> temp;
  for (long long i = 0; i < n; i++) {
    if (a[i]) temp.insert(a[i]);
  }
  long long ans2 = 1e18;
  long long pos = -1;
  for (long long i = 0; i < n; i++) {
    if (b[i] == 1) pos = i;
  }
  if (pos > -1) {
    long long f = 0;
    for (long long i = pos + 1; i < n; i++) {
      if ((b[i] < b[i - 1]) || (b[i] > b[i - 1] && b[i] - b[i - 1] > 1)) {
        f = 1;
        break;
      }
    }
    if (!f) {
      long long cnt = 0;
      long long num = b[n - 1];
      long long pos = 0;
      long long ch = 0;
      while (pos < n && num < n) {
        if (temp.find(num + 1) == temp.end()) {
          ch = 1;
          break;
        }
        temp.insert(b[pos]);
        num = num + 1;
        cnt++;
        pos++;
      }
      if (!ch) ans2 = cnt;
    }
  }
  cout << min(ans + n, ans2);
}
