#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
long long A[maxn], B[maxn], cnt[maxn];
long long n;
long long work(long long a[], long long b[]) {
  long long ans = 0, pos = 1;
  while (b[pos] != 1) ++pos;
  memset(cnt, 0, sizeof cnt);
  for (int i = 1; i <= n; i++) cnt[b[i]] = i;
  if (pos <= n) {
    bool flag = true;
    for (int i = pos, k = 1; i <= n; i++, k++) {
      if (b[i] != k) flag = false;
    }
    if (flag) {
      for (int i = 1; i < pos; i++) {
        if (b[i] == 0) continue;
        if (n - pos + 2 + i > b[i]) flag = false;
      }
    }
    if (flag)
      return pos - 1;
    else {
      ans = pos + 1;
    }
  } else {
    ans = 1;
  }
  for (int i = 2; i <= n; i++) {
    if (cnt[i] <= ans)
      ans++;
    else
      ans += cnt[i] - ans + 1;
  }
  return ans;
}
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> A[i];
  }
  for (long long i = 1; i <= n; i++) {
    cin >> B[i];
  }
  cout << work(A, B) << endl;
  return 0;
}
