#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 2e5 + 5;
vector<int> a(N), b(2 * N);
int f() {
  int ans = 0;
  for (int i = 1; i < n + 1; ++i) {
    if (b[i]) {
      ans = max(ans, i - b[i] + 1);
    }
  }
  return ans + n;
}
int s() {
  set<int> s;
  for (int i = 1; i < n + 1; ++i)
    if (a[i]) s.insert(a[i]);
  int i = 1, ans = 0;
  while (!s.empty() and ans < n) {
    b[i + n] = *s.begin();
    s.erase(s.begin());
    if (b[i]) s.insert(b[i]);
    i++;
    ans++;
  }
  for (int j = 1; j < n + 1; ++j) {
    if (b[i + j - 1] != j) return 2e9;
  }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for (int i = 1; i < n + 1; ++i) cin >> a[i];
  for (int i = 1; i < n + 1; ++i) cin >> b[i];
  cout << min(f(), s()) << "\n";
  return 0;
}
