#include <bits/stdc++.h>
using namespace std;
long long n, a[200010], b[200010];
long long solve() {
  int onep = -1;
  for (int i = 0; i < n; i++)
    if (b[i] == 1) onep = i;
  if (-1 == onep) return 1e9;
  for (int i = onep; i < n; i++) {
    if (b[i] != i + 1 - onep) return 1e9;
  }
  for (int i = 0; i < onep; i++) {
    if (b[i] == 0) continue;
    if (i + 2 > onep - (n - b[i])) return 1e9;
  }
  return onep;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  for (int i = 0; i < n; i++) scanf("%lld", &b[i]);
  long long ans = solve();
  long long t = n;
  for (int i = 0; i < n; i++) {
    if (b[i] == 0) continue;
    t = max(t, i + 2 + (n - b[i]));
  }
  ans = min(ans, t);
  cout << ans << endl;
  return 0;
}
