#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, a[N], b[N], pos;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    cin >> b[i];
    if (b[i] == 1) pos = i;
  }
  if (pos) {
    bool flag = true;
    for (int i = pos + 1; i <= n; ++i)
      if (b[i] != b[i - 1] + 1) {
        flag = false;
        goto out;
      }
    if (pos == 1) {
      cout << 0 << endl;
      return 0;
    }
    for (int i = 1; i < pos; ++i) {
      if (!b[i]) continue;
      if (i - (b[i] - (n - pos + 1)) >= 0) {
        flag = false;
        goto out;
      }
    }
    cout << pos - 1 << endl;
    return 0;
  }
out:;
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    if (b[i]) ans = max(ans, i - b[i] + 1);
  cout << ans + n << endl;
  return 0;
}
