#include <bits/stdc++.h>
const double PI = acos(-1.0);
const int N = (int)2e5 + 10;
using namespace std;
int a[N], b[N], pos[N];
int main() {
  int n;
  cin >> n;
  for (int i = (1); i <= (n); i++) {
    cin >> a[i];
    pos[a[i]] = 0;
  }
  for (int i = (1); i <= (n); i++) {
    cin >> b[i];
    pos[b[i]] = i;
  }
  if (pos[1]) {
    int i;
    for (i = 2; i <= n && pos[i] == pos[1] + i - 1; ++i)
      ;
    if (pos[i - 1] == n) {
      int j;
      for (j = i; pos[j] <= j - i && j <= n; ++j)
        ;
      if (j > n) {
        cout << n - i + 1 << endl;
        return 0;
      }
    }
  }
  int ans = -0x3f3f3f3f;
  for (int i = (1); i <= (n); i++) {
    ans = max(ans, pos[i] - i + 1);
  }
  cout << ans + n << endl;
  return 0;
}
