#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 10;
long long n, a[maxn], b[maxn], ma;
long long vis[maxn], arr[maxn];
long long res, pos;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    vis[a[i]] = 1;
  }
  for (long long i = 1; i <= n; i++) {
    cin >> b[i];
    arr[b[i]] = i;
  }
  if (vis[1]) {
    for (long long i = 2; i <= n; i++) {
      if (vis[i] == 0) {
        if (arr[i] - i + 1 >= res) res = arr[i] - i + 1;
      }
    }
    cout << res + n << endl;
    return 0;
  }
  long long j;
  for (j = arr[1] + 1; j <= n; j++) {
    if (b[j] == b[j - 1] + 1)
      continue;
    else
      break;
  }
  if (j > n) {
    for (long long i = b[n] + 1; i <= n; i++) {
      if (!vis[i]) res = max(res, arr[i] + b[n] - i + 1);
    }
    if (res == 0) {
      cout << n - (b[n] - b[arr[1]] + 1) << endl;
      return 0;
    }
  }
  res = 0;
  for (long long i = 2; i <= n; i++) {
    long long kkk = arr[i] - arr[1] + 1 - i;
    if (kkk > res) res = kkk;
  }
  cout << arr[1] + res + n << endl;
  return 0;
}
