#include <bits/stdc++.h>
using namespace std;
int n;
int a[200010], b[200010], c[200010];
int pos1 = 0, ans = 0;
bool satify(int num) {
  for (int i = num + 1; i <= n; ++i) {
    if (b[i] != 12345678 && b[i] <= i - num) return false;
  }
  return true;
}
int main() {
  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);
    if (b[i] == 1) pos1 = i;
    if (!b[i]) b[i] = 12345678;
  }
  for (int i = 1; i <= n; ++i) c[i] = b[i] - i;
  bool tail = (pos1 != 0);
  for (int i = pos1; tail && i <= n; ++i) tail = (i - pos1 + 1 == b[i]);
  if (tail) {
    for (int i = 1; i < pos1; ++i) {
      if (b[i] - (n - pos1 + 1) <= i) {
        tail = false;
        break;
      }
    }
    if (tail) ans = pos1 - 1;
  }
  if (!tail) {
    int low = -1, high = n + 1;
    while (low < high - 1) {
      int mid = (low + high) / 2;
      if (satify(mid))
        high = mid;
      else
        low = mid;
    }
    if (high == n + 1)
      ans = 2 * n;
    else
      ans = n + high;
  }
  printf("%d\n", ans);
  return 0;
}
