#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, k = 0, l = 0, flag = 0;
  int a[200005] = {0}, b[200005] = {0};
  cin >> n;
  l = n + 1;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != 0) flag = 1;
  }
  for (i = 1; i <= n; i++) {
    cin >> b[i];
    if (b[i] == 1) l = i;
  }
  for (i = l; i <= n; i++) {
    if (i == l && b[l] == 1)
      k = l;
    else if (b[i] - 1 == b[i - 1]) {
      k = i;
    } else {
      k = 0;
      break;
    }
  }
  if (l == 1 && k == n) {
    cout << 0 << endl;
    return 0;
  }
  if (flag == 0 || k != n) {
    l = n + 1;
    k = 0;
  }
  int mx = 0;
  for (i = 1; i < l; i++) {
    int p = b[i] - b[k] - 1;
    if (b[i] != 0 && i - p > mx) {
      mx = i - p;
    }
  }
  if (mx > 0 && l != n + 1) {
    k = 0;
    for (i = l; i <= n; i++) {
      int p = b[i] - b[k] - 1;
      if (b[i] != 0 && i - p > mx) {
        mx = i - p;
      }
    }
  }
  if (mx > 0 || l == n + 1)
    cout << mx + n << endl;
  else
    cout << n - b[k] << endl;
}
