#include <bits/stdc++.h>
using namespace std;
int pos[200000 + 10], b[200000 + 10];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (x) {
      pos[x] = 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    if (b[i]) {
      pos[b[i]] = i;
    }
  }
  int start = 1;
  int end = b[n];
  bool flag = true;
  for (int i = n - 1, j = end - 1; j > 0; j--, i--) {
    if (b[i] != j) {
      flag = false;
    }
  }
  if (flag) {
    start = end + 1;
  }
  if (start != 1) {
    for (int i = start; i <= n; i++) {
      if (pos[i] > i - start) {
        start = 1;
        break;
      }
    }
  }
  int ans = n - start + 1;
  ans += pos[start];
  int mx = 0;
  for (int i = start + 1; i <= n; i++) {
    int t = pos[i] - pos[start];
    mx = max(mx, t - i + start);
  }
  cout << ans + mx << "\n";
}
