#include <bits/stdc++.h>
using namespace std;
int cnt;
int a[400010], b[400010], d[400010];
int n;
int v[400010];
void xiagao() {
  if (!v[1]) {
    for (int i = 1; i <= n; i++)
      if (b[i] == 1) {
        for (int j = i; j <= n; j++)
          if (b[j] != j - i + 1) {
            cnt = 0;
            break;
          } else
            cnt++;
        break;
      }
  }
  int f = 1;
  if (cnt != 0) {
    for (int i = 1; i <= n - cnt; i++) {
      if (d[i] + cnt > 0) {
        f = 0;
        break;
      }
    }
    if (f) {
      printf("%d\n", n - cnt);
      return;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans = max(ans, d[i]);
  printf("%d", ans + n);
}
int main() {
  memset(v, 0, sizeof(v));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    v[a[i]] = 1;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    d[i] = i - b[i] + 1;
  }
  for (int i = 1; i <= n; i++) {
    if (b[i] == 0) d[i] = -INT_MAX;
  }
  cnt = 0;
  xiagao();
  return 0;
}
