#include <bits/stdc++.h>
using namespace std;
const int inf = 2001000;
int a[200100], b[200100], cnt[200100];
int n, tot, res;
bool suc, hav;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    if (a[i] != 0) {
      cnt[a[i]] = -inf;
    }
  }
  hav = true;
  for (int i = 1; i <= n; i++) {
    b[i] = read();
    if (b[i] != 0) {
      hav = true;
      cnt[b[i]] = i + 1 - b[i];
    }
  }
  if (hav == false) {
    printf("%d\n", n);
    return 0;
  }
  if (cnt[1] == -inf) {
    for (int i = 1; i <= n; i++) res = max(res, cnt[i]);
    res += n;
    printf("%d\n", res);
    return 0;
  }
  int tmp = cnt[1];
  suc = true;
  for (int i = 1; i + tmp <= n + 1; i++) {
    if (cnt[i] != tmp) {
      suc = false;
    }
  }
  if (suc == true) {
    for (int i = n - tmp + 2; i <= n; i++) {
      if (cnt[i] > tmp - n - 1) {
        suc = false;
      }
    }
  }
  if (suc == true) {
    printf("%d\n", tmp - 1);
    return 0;
  } else {
    for (int i = 1; i <= n; i++) res = max(res, cnt[i]);
    res += n;
    printf("%d\n", res);
    return 0;
  }
  return 0;
}
