#include <bits/stdc++.h>
using namespace std;
int mas[1000000];
int n;
int gde[1000000];
bool check(int val) {
  for (int i = 2; i <= n; i++) {
    if (gde[i] != -1) {
      int pos = gde[i] + 1;
      if (pos >= val + i) {
        return false;
      }
    }
  }
  return true;
}
int BinarySearchLast(int indx) {
  int p = indx;
  int ost = n;
  while (p <= ost) {
    int mid = (p + ost) / 2;
    if (check(mid)) {
      ost = mid - 1;
    } else {
      p = mid + 1;
    }
  }
  return p;
}
int calcneedone(int indx) {
  indx++;
  int c = BinarySearchLast(indx);
  return c + n;
}
int findone() {
  int ans = -1;
  for (int i = 0; i < n; i++) {
    if (mas[i] == 1) {
      return i;
    }
  }
  return -1;
}
int main() {
  int a;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    gde[a] = -1;
  }
  for (int i = 0; i < n; i++) {
    cin >> mas[i];
    gde[mas[i]] = i;
  }
  int indx = findone();
  if (indx == -1) {
    cout << calcneedone(indx) << endl;
    return 0;
  }
  int p = 1;
  for (int i = indx; i < n; i++) {
    if (p == mas[i]) {
      p++;
    } else {
      cout << calcneedone(indx) << endl;
      return 0;
    }
  }
  for (int i = p; i <= n; i++) {
    if (gde[i] != -1) {
      int pos = gde[i] + 1;
      if (pos > i - p) {
        cout << calcneedone(indx) << endl;
        return 0;
      }
    }
  }
  cout << indx << endl;
}
