#include <bits/stdc++.h>
using namespace std;
int a = 0, b = 1, d = 1;
int ans1 = 0, ans2 = 0;
int max(int a, int b) { return a > b ? a : b; }
int main() {
  int n;
  scanf("%d", &n);
  ans2 = n;
  for (int i = 1; i <= n; i++) {
    int c;
    scanf("%d", &c);
  }
  for (int i = 1; i <= n; i++) {
    int c;
    scanf("%d", &c);
    if (a) {
      if (d != c) {
        b = 0;
      }
      d++;
    } else if (c == 1) {
      a = i;
      d++;
    } else if (c != 0)
      ans1 = max(ans1, n + 1 + i - c);
    if (c != 0) ans2 = max(ans2, n + 1 + i - c);
  }
  if (b == 0) {
    printf("%d\n", ans2);
    return 0;
  }
  if (a - 1 >= ans1) {
    printf("%d\n", a - 1);
    return 0;
  }
  printf("%d\n", ans2);
  return 0;
}
