#include <bits/stdc++.h>
using namespace std;
const int mxn = 262144, md = 998244353;
int rd() {
  int x = 0, flg = 1;
  char c = getchar();
  for (; (c < 48 || c > 57) && c != '-'; c = getchar())
    ;
  if (c == '-') flg = -1, c = getchar();
  for (; c > 47 && c < 58; x = x * 10 + c - 48, c = getchar())
    ;
  return x * flg;
}
int n, exist[mxn], a[mxn];
bool solve(int x, int y) {
  if (x > n) return 1;
  if (!exist[x])
    return 0;
  else
    return exist[a[y]] = 1, solve(x + 1, y + 1);
}
int main() {
  n = rd();
  for (int i = 1; i <= n; ++i) a[i] = rd(), exist[a[i]] = 1;
  for (int i = 1; i <= n; ++i) a[i] = rd();
  int cur = 0;
  for (int i = 1; i <= n; ++i)
    if (a[i] == cur + 1)
      ++cur;
    else
      cur = 0;
  if (cur && solve(cur + 1, 1)) return printf("%d\n", n - cur), 0;
  int mx = 0;
  for (int i = 1; i <= n; ++i)
    if (a[i] && mx < i - a[i] + 1) mx = i - a[i] + 1;
  printf("%d\n", mx + n);
  return 0;
}
