#include <bits/stdc++.h>
#pragma warning(disable : 4996)
const long long MOD = 1000000007;
using namespace std;
int main(int argc, char* argv[]) {
  int n;
  scanf("%d", &n);
  vector<int> a(n), b(n);
  int found = -1;
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    if (b[i] == 1) found = i;
  }
  if (found >= 0) {
    int bad = 0;
    for (i = found; i < n; i++) {
      if (b[i] != (i - found + 1)) {
        bad = 1;
        break;
      }
    }
    int next = n - found + 1;
    if (bad == 0) {
      for (i = 0; i < found; i++) {
        if (b[i] > 0 && i + 1 > b[i] - next) {
          bad = 1;
          break;
        }
      }
    }
    if (bad == 0) {
      printf("%d\n", n - next + 1);
      return 0;
    }
  }
  int wait = 0;
  for (i = 0; i < n; i++) {
    if (b[i] > 0) {
      int tmp = i - (b[i] - 1) + 1;
      tmp = ((tmp) < (0) ? (0) : (tmp));
      wait = ((wait) < (tmp) ? (tmp) : (wait));
    }
  }
  printf("%d\n", wait + n);
  return 0;
}
