#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn], b[maxn];
int p[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  memset(p, 0, sizeof(p));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    p[b[i]] = i;
  }
  if (p[1]) {
    for (int i = 1; p[i] == p[1] + i - 1; i++) {
      if (p[i] == n) {
        int k = i + 1;
        for (; k <= n && p[k] <= k - i - 1; k++)
          ;
        if (k > n) {
          printf("%d\n", n - i);
          return 0;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, p[i] - i + 1 + n);
  }
  printf("%d\n", ans);
  return 0;
}
