#include <bits/stdc++.h>
using namespace std;
int n;
int a[200005], b[200005], wz[200005];
int main() {
  int i, j;
  cin >> n;
  for (i = 1; i <= n; ++i) cin >> a[i];
  for (i = 1; i <= n; ++i) cin >> b[i], wz[b[i]] = i;
  int t = b[n] - 1, ok = 1;
  for (i = n - 1; i; --i) {
    if (!t) break;
    if (b[i] != t) {
      ok = 0;
      break;
    }
    --t;
  }
  if (ok) {
    int ok2 = 1;
    for (i = b[n] + 1; i <= n; ++i) {
      if (wz[i] - (i - b[n] - 1) > 0) {
        ok2 = 0;
        break;
      }
    }
    if (ok2) {
      cout << n - b[n] << endl;
      return 0;
    }
  }
  int mx = 0;
  for (i = 1; i <= n; ++i) mx = max(mx, wz[i] - i + 1);
  cout << mx + n << endl;
  return 0;
}
