#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926536;
const long long prime = 1e9 + 7;
const long long maxN = 1e5 + 5;
const long long maxans = 4294967296;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, ans = 0, pos = 0, k, hand = 0;
  cin >> n;
  k = n;
  long long a[n + 2], b[n + 2];
  b[0] = 0;
  for (long long i = (long long)(1); i <= (long long)(n); i++) {
    cin >> a[i];
    if (a[i] > 0) {
      hand++;
    }
  }
  for (long long i = (long long)(1); i <= (long long)(n); i++) {
    cin >> b[i];
    if (b[i] == 1) {
      pos = i;
    }
  }
  if (pos > 0) {
    for (long long i = (long long)(pos); i <= (long long)(n); i++) {
      if (b[i] != i - pos + 1) {
        break;
      }
      if (i == n) {
        k = pos - 1;
      }
    }
    if (b[pos - 1] != 0) {
      k = n;
    }
    if (k == pos - 1) {
      for (long long i = (long long)(1); i <= (long long)(pos - 1); i++) {
        if (b[i] > 0) {
          hand++;
          if (b[i] < b[n] + 1 + i) {
            k = n;
            break;
          }
        }
        if ((i == pos - 2) || (hand + b[n] == n)) {
          cout << n - b[n];
          return 0;
        }
      }
    }
  } else {
    ans = n;
  }
  for (long long i = (long long)(1); i <= (long long)(k); i++) {
    if (b[i] > 0) {
      ans = max(ans, i - b[i] + 1 + n);
    }
  }
  cout << ans;
  return 0;
}
