#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n + 1], b[n + 1], access[n + 1];
  for (int i = 1; i <= n; i++) cin >> a[i], access[a[i]] = 1;
  for (int i = 1; i <= n; i++) cin >> b[i], access[b[i]] = i + 1;
  int x = 0, y = 1, z, ans = 0;
  for (int i = 1; i <= n; i++)
    if (b[i] == 1) x = i;
  if (x)
    for (int i = x + 1; i <= n; i++)
      if (b[i] - b[i - 1] != 1) y = 0;
  if (x && y) {
    z = n - x + 2;
    for (int i = z; i <= n; i++) {
      if (access[i] > (i - z + 1)) y = 0;
    }
  }
  if (!x || y == 0) {
    for (int i = 2; i <= n; i++) {
      ans = max(ans, (access[i] - (access[1] + (i - 1))));
    }
    cout << access[1] + ans + (n - 1);
    return 0;
  } else {
    cout << n - z + 1;
  }
}
