#include <bits/stdc++.h>
using namespace std;
int a[200010], b[200010], n, i, s = 0;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (i = 1; i <= n; i++)
    if (b[n - i + 1] && (b[n - i + 1] == b[n] - i + 1))
      s++;
    else
      break;
  if (s == b[n]) {
    for (i = 1; i <= n - s; i++)
      if (b[i] && (i - (b[i] - s - 1) > 0)) break;
    if (i > n - s) {
      printf("%d\n", n - s);
      return 0;
    }
  }
  s = 0;
  for (i = 1; i <= n; i++)
    if (b[i]) s = max(s, i - (b[i] - 1));
  printf("%d\n", n + s);
  return 0;
}
