#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int arr[200009], n, ans;
set<int> s;
vector<int> v, g;
bool f() {
  int now = v.size();
  for (int i = 1; i <= n; i++) s.insert(arr[i]);
  for (int i = 0; i < g.size(); i++) {
    now++;
    if (!s.count(now)) return 0;
    s.erase(now);
    s.insert(g[i]);
  }
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", arr + i);
  if (n == 1) {
    if (arr[1])
      puts("1");
    else
      puts("0");
    return 0;
  }
  int ok = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    if (x) umax(ans, i - x + 1);
    if (x == 1) ok = 1;
    if (ok)
      v.push_back(x);
    else
      g.push_back(x);
  }
  ok = 1;
  for (int i = 0; i < v.size(); i++) ok &= (v[i] == i + 1);
  if (ok and v.size() != 0)
    if (f()) return printf("%d\n", n - v.size()) * 0;
  cout << ans + n << endl;
  return 0;
}
