#include <bits/stdc++.h>
using namespace std;
int many;
int at[200010];
int hd[200010];
int cd[200010];
int give = 0;
int main() {
  cin >> many;
  for (int i = 1; i <= many; i++) {
    scanf("%d", &hd[i]);
    at[hd[i]] = 0;
  }
  for (int i = 1; i <= many; i++) {
    scanf("%d", &cd[i]);
    at[cd[i]] = i;
  }
  if (at[1]) {
    int i;
    for (i = 2; at[i] == at[1] + i - 1; i++)
      ;
    if (at[i - 1] == many) {
      int j;
      for (j = i; j <= many && at[j] <= j - i; j++)
        ;
      if (j == many + 1) {
        cout << at[1] - 1;
        return 0;
      }
    }
  }
  for (int i = 1; i <= many; i++) give = max(give, at[i] - i + 1 + many);
  cout << give;
  return 0;
}
