#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
long long int n, a[N], b[N], p[N], ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i, j;
  cin >> n;
  for (i = 1; i <= n; ++i) {
    cin >> a[i];
    p[a[i]] = 0;
  }
  for (i = 1; i <= n; ++i) {
    cin >> b[i];
    p[b[i]] = i;
  }
  if (p[1]) {
    for (i = 2; p[i] == p[1] + i - 1; ++i)
      ;
    if (p[i - 1] == n) {
      for (j = i; j <= n && p[j] <= j - i; ++j)
        ;
      if (j > n) {
        cout << n - i + 1 << endl;
        return 0;
      }
    }
  }
  for (i = 1; i <= n; ++i) ans = max(ans, p[i] - i + 1 + n);
  cout << ans << endl;
  return 0;
}
