#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<> dis(0, 1000000000 << 1);
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int N = 200001;
int a[N], b[N], t[N];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    t[b[i]] = i;
  }
  int idx = n;
  while (b[idx - 1] >= 1 and b[idx - 1] + 1 == b[idx]) idx--;
  if (b[idx] == 1) {
    int x = n - idx + 1;
    bool f = true;
    for (int i = x + 1; i <= n; i++)
      if (t[i] > i - x - 1) f = false;
    if (f) {
      cout << idx - 1 << endl;
      return 0;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans = max(ans, t[i] - i + 1);
  ans += n;
  cout << ans << endl;
  return 0;
}
