#include <bits/stdc++.h>
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n;
const int N = 2e5 + 10;
int a[N];
int b[N];
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  int pos = 0;
  for (int i = 1; i <= n; i++) {
    b[i] = read();
    if (b[i] == 1) pos = i;
  }
  if (pos) {
    bool flag = true;
    for (int i = pos + 1; i <= n; i++)
      if (b[i - 1] + 1 != b[i]) {
        flag = false;
        break;
      }
    if (flag) {
      int k = n - pos + 1;
      for (int i = 1; i <= pos - 1; i++) {
        if (b[i] && b[i] <= k + i) {
          flag = false;
          break;
        }
      }
      if (flag) {
        cout << pos - 1 << endl;
        return 0;
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    if (b[i]) ans = max(ans, (long long)i - b[i] + 1);
  cout << ans + n << endl;
  return 0;
}
