#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const int INF32 = 0x3f3f3f3f;
const long long INF64 = 0x3f3f3f3f3f3f3f3f;
const long long MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1.0e-8;
int A[MAXN], B[MAXN];
int Pos[MAXN], Cnt[MAXN];
int n;
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; ++i) Pos[i] = 0;
    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] > 0) Pos[B[i]] = i;
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      if (Pos[i] < i)
        Cnt[i] = Pos[i] + n - i + 1;
      else
        Cnt[i] = Pos[i] - i;
    }
    for (int i = 1; i <= n; ++i) ans = max(ans, Cnt[i]);
    int flag = 1;
    while (flag) {
      flag = 0;
      for (int i = 1; i <= n; ++i) {
        if (Pos[i] == 0) continue;
        if (ans > Cnt[i]) Cnt[i] = Pos[i] + n - i + 1;
        if (ans < Cnt[i]) {
          ans = Cnt[i];
          flag = 1;
        }
      }
    }
    printf("%d\n", ans);
  }
}
