#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long mod = 1e9 + 7;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, x;
  cin >> n;
  vector<long long> d1(n + 1, 0), d2(n + 1, 0);
  for (long long i = 0; i < n; i++) {
    cin >> x;
    d1[x] = 1;
    d2[x] = 1;
  }
  queue<long long> q1, q2;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> x;
    a[i] = x;
    q1.push(x);
    q2.push(x);
  }
  x = n - 1;
  bool flag = false;
  if (a[x] == 1) flag = true;
  while (x > 0) {
    if (a[x] != a[x - 1] + 1) break;
    if (a[x - 1] == 1) flag = true;
    x--;
  }
  if (flag) {
    long long ans = 0;
    while (q1.back() != n) {
      x = q1.back() + 1;
      if (d1[x] == 0) break;
      q1.push(x);
      x = q1.front();
      q1.pop();
      d1[x] = 1;
      ans++;
    }
    if (q1.back() == n) {
      cout << ans;
      return 0;
    }
  }
  stack<long long> s1;
  s1.push(0);
  long long ans = 0;
  while (q2.size() != 0) {
    long long y = s1.top() + 1;
    if (d2[y] == 1) s1.push(y);
    x = q2.front();
    q2.pop();
    d2[x] = 1;
    ans++;
  }
  x = s1.top();
  ans += (n - x);
  cout << ans;
  return 0;
}
