#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[2][n];
  int prev = -1, one = -1, seq = -1, last = -1;
  for (int i = 0; i < n; i++) cin >> a[0][i];
  for (int i = 0; i < n; i++) {
    cin >> a[1][i];
    if (a[1][i]) {
      last = i;
      if (a[1][i] == 1) {
        one = i;
        seq = 1;
        continue;
      } else if (one == -1) {
        prev = i;
      }
    }
    if (seq != -1) {
      if (a[1][i] == a[1][i - 1] + 1)
        seq++;
      else
        seq = -1;
    }
  }
  if (one != -1) {
    if (seq != -1) {
      if (prev == -1) {
        cout << one << endl;
        return 0;
      } else {
        int i;
        for (i = 0; i < one; i++) {
          if (a[1][i] && i > a[1][i] - 2 - n + one) break;
        }
        if (i == one) {
          cout << one << endl;
          return 0;
        }
      }
    }
    int start = one + 1;
    int shift = 0;
    for (int k = one + 1; k < n; k++) {
      if (a[1][k]) {
        int s = start + a[1][k] - 2;
        if (k > s) {
          shift = (k - s);
          start += shift;
        }
      }
    }
    cout << n + start << endl;
  } else {
    if (last != -1) {
      int start = 0;
      int shift = 0;
      for (int k = 0; k < n; k++) {
        if (a[1][k]) {
          int s = start + a[1][k] - 2;
          if (k > s) {
            shift = (k - s);
            start += shift;
          }
        }
      }
      cout << n + start << endl;
    } else
      cout << n;
  }
}
