#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n], b[n], access[n + 1], last = -1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    access[a[i]] = 0;
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    access[b[i]] = i + 1;
    if (last >= 0 && b[i] == b[i - 1] + 1) ++last;
    if (b[i] == 1) last = i;
  }
  if (last == n - 1) {
    bool flag = true;
    for (int cnt = 0; cnt < access[1] - 1; ++cnt)
      if (access[n - access[1] + 2 + cnt] > cnt) flag = false;
    if (flag) {
      cout << access[1] - 1;
      return;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans = max(ans, access[i] - i + 1);
  cout << n + ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
