#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N], b[N], p[N];
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", b + i);
    p[b[i]] = i;
  }
  if (n == 1) {
    if (b[1] == 1)
      puts("0");
    else
      puts("1");
    return 0;
  }
  if (b[n] != 0) {
    int ok = 1, i = n;
    while (b[i] != 0) {
      if (b[i] == 1) break;
      if (b[i - 1] + 1 == b[i])
        i--;
      else {
        ok = 0;
        break;
      }
    }
    int ans = 0;
    if (ok) {
      ans = b[n];
      for (int i = 1; i <= n; i++) {
        if (b[i] > b[n] && (b[i] - ans) <= i) {
          ok = 0;
          break;
        }
      }
    }
    if (ok) {
      ans = n - ans;
      printf("%d\n", ans);
      return 0;
    }
  }
  int ans = n;
  for (int i = 1; i <= n; i++) {
    if (b[i]) {
      ans = max(i - b[i] + n + 1, ans);
    }
  }
  printf("%d\n", ans);
}
