#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn];
int tempo[maxn];
int main(void) {
  memset(tempo, -1, sizeof tempo);
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    if (x != 0) tempo[x] = 1;
  }
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  bool ok = 1;
  int pos = -1;
  for (int i = 1; i <= n; i++)
    if (a[i] == 1) pos = i;
  if (pos != -1) {
    for (int i = pos + 1; i <= n; i++)
      if (a[i] != a[i - 1] + 1) ok = 0;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 0) continue;
    if (tempo[a[i]] == -1) tempo[a[i]] = i + 1;
  }
  int ans = 2 * n + 1;
  int first = 0;
  for (int i = 1; i <= n; i++) first = max(first, max(1, tempo[i] - (i - 1)));
  int k = 1;
  for (int i = a[n] + 1; i <= n; i++) {
    int delta = i - a[n];
    k = max(k, max(1, tempo[i] - (delta - 1)));
  }
  ans = first + n - 1;
  if (ok) {
    if (k + n - a[n] - 1 < pos) ans = min(ans, k + n - a[n] - 1);
  }
  printf("%d\n", ans);
}
