#include <bits/stdc++.h>
using namespace std;
int n, at, ans = INT_MAX;
int a[200001], b[200001], pos[200001];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    pos[b[i]] = i;
  }
  for (int i = 1; i <= n; i++) at = max(at, pos[i] - i + n + 1);
  for (int i = 1; i <= n; i++) {
    if (pos[i] >= i) {
      ans = pos[i] - i;
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    if ((pos[i] < i && ans < pos[i] - i + n + 1) ||
        (pos[i] >= i && ans != pos[i] - i)) {
      ans = INT_MAX;
      break;
    }
  }
  if (ans == INT_MAX)
    cout << at << endl;
  else
    cout << ans << endl;
  return 0;
}
