#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const double PI = 4 * atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAX_N = 2e6 + 10;
int n;
int a[MAX_N], b[MAX_N], p[MAX_N];
void solve() {
  for (int i = 1; i <= n; ++i) {
    p[b[i]] = i;
  }
  if (p[1]) {
    int i = 2;
    for (; p[i] == p[1] + i - 1; ++i)
      ;
    if (p[i - 1] == n) {
      int j;
      for (j = i; j <= n && p[j] <= j - i; ++j)
        ;
      if (j > n) {
        cout << n - i + 1 << '\n';
        return;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans = max(ans, p[i] - i + 1 + n);
  cout << ans << '\n';
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) cin >> b[i];
  solve();
  return 0;
}
