#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, hands[200010], pile[200010], a[200010] = {0}, cnt = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &hands[i]);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &pile[i]);
  }
  for (int i = 0; i < n; ++i) {
    if (pile[i] == 1) {
      cnt = 1;
      for (int j = i + 1; j < n; ++j) {
        ++cnt;
        if (pile[j] != pile[j - 1] + 1) {
          cnt = 0;
          break;
        }
      }
      break;
    }
  }
  for (int i = 1; i <= n; ++i) {
    a[pile[i - 1]] = max(0, i - pile[i - 1] + 1 + cnt);
  }
  int mx = a[1];
  for (int i = 2; i <= n; ++i) {
    mx = max(mx, a[i]);
  }
  int check = 1;
  for (int i = cnt + 1; i <= n; ++i) {
    if (a[i] != 0) {
      check = 0;
      break;
    }
  }
  if (check)
    printf("%d", n - cnt);
  else
    printf("%d", mx + n - cnt);
  return 0;
}
