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