#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline int Chkmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
inline int Chkmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline T read() {
  T sum = 0;
  int fl = 1, ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') fl = -1;
  for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
  return sum * fl;
}
const int maxn = 200000 + 5;
int n, m, a[maxn], b[maxn];
int f[maxn];
int main() {
  n = read<int>();
  for (int i = 1; i <= n; i++) {
    a[read<int>()] = 1;
  }
  for (int i = 1; i <= n; i++) {
    b[i] = read<int>();
    f[b[i]] = i;
  }
  if (f[1]) {
    m = n - f[1] + 1;
    for (int i = f[1]; i <= n; i++) {
      if (b[i] != i - f[1] + 1) {
        m = 0;
        break;
      }
    }
    for (int i = m + 1; i <= n; i++) {
      if (f[i] >= i - m) {
        m = 0;
        break;
      }
    }
    if (m) {
      printf("%d\n", n - m);
      return 0;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    Chkmax(ans, f[i] - i + 1);
  }
  printf("%d\n", n + ans);
  return 0;
}
