#include <bits/stdc++.h>
using namespace std;
int n;
int a[200005];
int b[200005];
int pos[200005];
bool ok;
int ans = 0;
int max(int a, int b) { return a > b ? a : b; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    pos[a[i]] = 0;
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &b[i]);
    pos[b[i]] = i;
  }
  if (pos[1] != 0) {
    ok = true;
    int i;
    for (i = 2; i <= n; ++i) {
      if (pos[i] != pos[1] + i - 1) {
        break;
      }
    }
    if (pos[i - 1] == n) {
      for (int j = i; j <= n; ++j) {
        if (pos[j] > j - i) {
          ok = false;
          break;
        }
      }
      if (ok == true) {
        printf("%d\n", n - i + 1);
        return 0;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    ans = max(ans, pos[i] - i + 1 + n);
  }
  printf("%d\n", ans);
  return 0;
}
