#include <bits/stdc++.h>
using namespace std;
int n;
int p[200100];
int d[200100];
int check(int m) {
  int x = 1;
  if (m == 0) {
    for (int i = 1; i <= n; i++) {
      if (d[i] == x)
        x++;
      else {
        if (x > 1) {
          x = 1;
          break;
        }
      }
    }
  }
  if (x > n) return 0;
  for (int i = x; i <= n; i++) {
    if (p[i] > (m + i - x)) {
      return -1;
    }
  }
  return m + n - x + 1;
}
int solve() {
  int l = 1;
  int r = n;
  int ans = check(0);
  if (ans != -1) return ans;
  while (l <= r) {
    int mid = (l + r) / 2;
    int res = check(mid);
    if (res != -1) {
      ans = res;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int tmp;
    scanf("%d", &tmp);
    if (tmp) p[tmp] = 0;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    if (d[i]) p[d[i]] = i;
  }
  int ans = solve();
  printf("%d\n", ans);
  return 0;
}
