#include <bits/stdc++.h>
using namespace std;
const int N = 210000;
const long long mod = 1e9 + 7;
int a[N], b[5 * N], head, tail;
int n;
priority_queue<int, vector<int>, greater<int> > q;
int ans;
int check(int x) {
  while (!q.empty()) q.pop();
  for (int i = 1; i <= n; i++)
    if (a[i]) q.push(a[i]);
  head = 1, tail = n;
  int cnt = 0;
  for (int i = 1; i <= x; i++) {
    if (q.size() == n) break;
    if (b[head]) q.push(b[head]);
    head++;
    b[++tail] = 0;
    cnt++;
  }
  while (!q.empty()) {
    b[++tail] = q.top();
    q.pop();
    if (b[head]) q.push(b[head]);
    head++;
    cnt++;
  }
  int flag = 0;
  for (int i = head, j = 1; i <= tail; i++, j++)
    if (b[i] != j) flag = 1;
  if (flag == 0) ans = cnt;
  return flag == 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i]) q.push(a[i]);
  }
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  head = 1, tail = n;
  while (!q.empty()) {
    b[++tail] = q.top(), q.pop();
    if (b[head]) q.push(b[head]);
    head++;
  }
  int flag = 0;
  for (int i = head, j = 1; i <= tail; i++, j++)
    if (b[i] != j) flag = 1;
  if (!flag) {
    printf("%d\n", head - 1);
    return 0;
  }
  int l = 1, r = n;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", ans);
  return 0;
}
