#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)2e5 + 5;
int inhand[maxn], pile[maxn];
int pos[maxn];
int main() {
  int n;
  while (cin >> n) {
    memset(inhand, 0, sizeof inhand);
    memset(pos, 0, sizeof pos);
    memset(pile, 0, sizeof pile);
    for (int i = 1; i <= n; i++) cin >> inhand[i];
    for (int i = 1; i <= n; i++) {
      cin >> pile[i];
      pos[pile[i]] = i;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) ans = max(ans, pos[i] + 1 + n - i);
    if (pos[1]) {
      bool flagA = 1, flagB = 1;
      int last, en = n;
      for (int i = pos[1]; i <= n; i++) {
        if (pile[i] - 1 == i - pos[1]) {
          last = pile[i];
          continue;
        }
        flagA = 0;
      }
      if (flagA) {
        for (int i = last + 1; i <= n; i++) {
          if (pos[i] < i - last) {
            en = i;
            continue;
          }
          flagB = 0;
        }
      }
      if (flagA && flagB) ans = min(ans, en - last);
    }
    cout << ans << endl;
  }
}
