#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, a[N], b[N], pos[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) cin >> b[i];
  for (int i = 1; i <= n; ++i) {
    pos[a[i]] = 0;
    pos[b[i]] = i;
  }
  bool useExist = 1;
  if (pos[1] == 0) useExist = 0;
  int j = 1;
  for (int i = pos[1]; i <= n; ++i) {
    if (b[i] != j) {
      useExist = 0;
      break;
    }
    j++;
  }
  j = b[n];
  for (int i = 1; i + j <= n; ++i) {
    if (pos[i + j] > i - 1) {
      useExist = 0;
      break;
    }
  }
  if (useExist) {
    cout << n - b[n] << endl;
  } else {
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      if (pos[i] <= ans)
        ans++;
      else
        ans = pos[i] + 1;
    }
    cout << ans << endl;
  }
  return 0;
}
