#include <bits/stdc++.h>
using namespace std;
long long int arr1[200005] = {0};
long long int arr2[200005] = {0};
long long int arr3[200005] = {0};
int main() {
  long long int n;
  long long int flag = 1;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> arr1[i];
  }
  for (long long int i = 0; i < n; i++) {
    cin >> arr2[i];
  }
  long long int a = 0;
  while (a < n) {
    if (arr2[a] == 1) break;
    a++;
  }
  if (a == n)
    flag = 0;
  else
    flag = 1;
  for (long long int i = 0; i < n; i++) {
    arr3[arr1[i]] = -100000000;
  }
  for (long long int i = a + 1; i < n; i++) {
    if (arr2[i] == arr2[i - 1] + 1)
      continue;
    else {
      flag = 0;
      break;
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (arr2[i] != 0) {
      arr3[arr2[i]] = i - arr2[i] + 2;
    }
  }
  long long int max = 0;
  long long int x = 0;
  if (flag == 1) {
    x = arr2[n - 1];
    for (long long int i = x + 1; i <= n; i++) {
      if (arr3[i] + x > 0) max = i + 1;
    }
    if (max == 0) {
      cout << max + n - x << endl;
      return 0;
    } else {
      cout << n + a + 1 << endl;
      return 0;
    }
  }
  for (long long int i = 1; i <= n; i++) {
    if (max < arr3[i]) max = arr3[i];
  }
  cout << max + n << endl;
  return 0;
}
