#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1000000007;
template <typename T>
void print(const vector<T> &v, bool add_one = false, int start = -1,
           int end = -1) {
  if (start < 0) start = 0;
  if (end < 0) end = int(v.size());
  for (int i = start; i < end; i++)
    cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}
void solve() {
  int N;
  cin >> N;
  vector<int> first(N), second(N);
  for (int i = 0; i < N; i++) cin >> first[i];
  for (int i = 0; i < N; i++) cin >> second[i];
  bool rem = false;
  bool one = false;
  int idx = 0;
  for (int i = 0; i < N; i++) {
    if (second[i] == 1) {
      if (i > 0) {
        if (second[i - 1] != 0) rem = true;
      }
      one = true;
      idx = i;
    } else if (one) {
      if (second[i] != second[i - 1] + 1) rem = true;
    }
  }
  int ans = 0;
  if (one && !rem) {
    for (int i = 0; i < idx; i++) {
      if (second[i] == 0) continue;
      if (i + 1 >= second[i] - second[N - 1]) {
        rem = true;
        break;
      }
    }
    if (!rem) ans = idx;
  }
  if (rem) {
    ans = idx + 1;
    int remove = 0;
    for (int i = idx + 1; i < N; i++) {
      if (second[i] == 0) continue;
      if (second[i] - 1 < i - idx) {
        remove = max(remove, ((i - idx) - (second[i] - 1)));
      }
    }
    ans += remove;
    ans += N;
  }
  if (!one) {
    int mn = INT_MAX;
    for (int i = 0; i < N; i++) {
      if (second[i] != 0) {
        mn = min(mn, second[i]);
        idx = i;
      }
    }
    if (mn == INT_MAX) {
      ans = N;
    } else {
      int remove = 0;
      for (int i = 0; i < N; i++) {
        if (second[i] == 0) continue;
        if (i > second[i] - 2) remove = max(remove, i - (second[i] - 2));
      }
      ans += remove;
      ans += N;
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  T = 1;
  while (T--) {
    solve();
  }
}
