#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  int a[n + 1];
  int b[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  int s = 0;
  for (int i = 1; i <= n; i++) {
    if (b[n - i + 1] > 0 && (b[n - i + 1] == b[n] - i + 1)) {
      s++;
    } else {
      break;
    }
  }
  if (s == b[n]) {
    int i;
    for (i = 1; i <= n - s; i++) {
      if (b[i] > 0 && (i - (b[i] - s - 1)) > 0) {
        break;
      }
    }
    if (i > n - s) {
      cout << n - s;
      return 0;
    }
  }
  s = 0;
  for (int i = 1; i <= n; i++) {
    if (b[i] > 0) {
      s = max(s, i - (b[i] - 1));
    }
  }
  cout << n + s;
  return 0;
}
