#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int base = 1e9;
const int MAX = 2 * 1e5;
const double EPS = 1e-9;
const double PI = acos(-1.);
const long long O = pow(2ll, 32) - 1;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), p(n + 2);
  int t = 0;
  for (int i = (0); i < (n); ++i) {
    cin >> a[i];
  }
  for (int i = (0); i < (n); ++i) {
    cin >> b[i];
    p[b[i]] = i + 1;
  }
  bool ok = false;
  if (p[1]) {
    ok = true;
    for (int i = (p[1]); i < (n); ++i) {
      if (b[i] != b[i - 1] + 1) {
        ok = false;
        break;
      }
    }
  }
  if (!ok) {
    for (int i = (1); i < (n + 1); ++i) {
      if (p[i])
        t = max(t, p[i] + 1 + n - i);
      else
        t = max(t, n - i + 1);
    }
  } else {
    for (int i = (b[n - 1] + 1); i < (n + 1); ++i) {
      if (p[i])
        t = max(t, p[i] + 1 + n - i);
      else
        t = max(t, n - i + 1);
    }
    if (t > p[1] - 1) t = max(t, p[1] + n);
  }
  cout << t;
  return 0;
}
