#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, k, i, p = 0, s = 0;
  cin >> n;
  vector<long> a(n + 1), b(n);
  for (i = 0; i < n; i++) cin >> s;
  s = -1;
  for (i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] != 0) a[b[i]] = i + 1;
  }
  s = 0;
  for (i = 2; i < n + 1; i++)
    if (a[i - 1] + 1 != a[i]) break;
  if (a[i - 1] == n) {
    for (; i < n + 1; i++) {
      if (a[i] <= s)
        s++;
      else
        break;
    }
    if (i == n + 1) {
      cout << s << endl;
      return 0;
    }
  }
  s = 0;
  for (i = 1; i < n + 1; i++) {
    if (a[i] <= s)
      s++;
    else
      s = a[i] + 1;
  }
  cout << s << endl;
  return 0;
}
