#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, m = 0;
  cin >> n;
  vector<int> a(n), b(n);
  set<int> s;
  s.insert(0);
  for (i = 0; i < n; ++i) cin >> a[i], s.insert(a[i]);
  for (i = 0; i < n; ++i) cin >> b[i];
  s.erase(0);
  for (i = 0; i < n; ++i)
    if (b[i]) m = max(m, i - b[i] + 1);
  for (i = 0; i < n + 1; ++i) {
    if (s.count(0)) s.erase(0);
    if (s.empty()) break;
    int x = *s.begin();
    if (b[i] == 1) break;
    b.push_back(x);
    s.erase(s.begin());
    s.insert(b[i]);
  }
  if (is_sorted(b.begin() + b.size() - n, b.end())) return cout << i, 0;
  cout << m + n + 1;
  return 0;
}
