#include <bits/stdc++.h>
using namespace std;
const int LEN = (int)2e5 + 1;
int n;
int w[LEN];
int ans;
int check() {
  if (w[1] && is_sorted(w + 1, w + n + 1)) return 0;
  int i = 1;
  int m = 0;
  if (w[i]) {
    while (w[i + 1] - 1 == w[i]) i++;
    m = i;
    i++;
    if (w[i] || w[i - 1] != n) return -1;
  };
  ;
  for (; i <= n; i++)
    if (w[i] > i - 1 - m) {
      return -1;
    }
  return n - m;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    w[x] = 0;
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    w[x] = i + 1;
  }
  ans = check();
  if (ans != -1) {
    cout << ans;
    return 0;
  };
  ;
  ans = n;
  for (int i = 1; i <= n; i++)
    if (w[i]) {
      ans = max(ans, n + w[i] - i + 1);
    }
  cout << ans;
  return 0;
}
