#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n], b[n];
  int valid = 0;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] != 0) {
      mp[a[i]] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] != 0) {
      mp[b[i]] = i + 1;
    }
    if (b[i] == valid + 1) {
      valid++;
    } else {
      valid = 0;
    }
  }
  if (!valid) {
    int reached = mp[1], cnt = 0;
    for (int i = 2; i <= n; i++) {
      if (reached + i - 1 + cnt >= mp[i]) {
        continue;
      } else {
        cnt += mp[i] - (reached + i - 1 + cnt);
      }
    }
    cout << mp[1] + n + cnt << endl;
  } else {
    bool v = true;
    int reached = 0, cnt = 0;
    for (int i = valid + 1; i <= n; i++) {
      if (reached + i - valid - 1 >= mp[i]) {
        continue;
      } else {
        v = false;
        break;
      }
    }
    if (v) {
      cout << n - valid << endl;
    } else {
      int reach = mp[1], cn = 0;
      for (int i = 2; i <= n; i++) {
        if (reach + i - 1 + cn >= mp[i]) {
          continue;
        } else {
          cn += mp[i] - (reach + i - 1 + cn);
        }
      }
      cout << mp[1] + n + cn << endl;
    }
  }
  return 0;
}
