#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  bool flag = false;
  int now = 0;
  for (int i = n - 1; i > 0; i--) {
    if (b[i] - b[i - 1] == 1) {
      flag = true;
      now = i - 1;
      if (b[i - 1] == 1) break;
    } else {
      flag = false;
      break;
    }
  }
  if (b[n - 1] == 1) {
    flag = true;
    now = n - 1;
  }
  if (flag) {
    bool flag1 = true;
    for (int i = 0; i < now; i++) {
      if (b[i] != 0 && i + 2 + b[n - 1] <= b[i]) {
        flag1 = true;
      } else if (b[i] != 0 && i + 2 + b[n - 1] > b[i]) {
        flag1 = false;
        break;
      }
    }
    if (flag1) {
      cout << now << endl;
      return 0;
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (b[i] != 0) {
      cnt = max(cnt, i - b[i] + 2);
    }
  }
  cout << n + cnt << endl;
  return 0;
}
