#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int b[maxn];
int a[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  int answer = 0;
  int flag = 0;
  int d = b[n];
  int k = n;
  while (b[k] > 1) {
    if (b[k] != b[k - 1] + 1) {
      flag = 1;
      break;
    }
    k--;
  }
  answer = k - 1;
  if (b[k] == 0) {
    k = n + 1;
    answer = n;
  };
  for (int i = 1; i < k; i++) {
    int t = 0;
    if (b[i] > 0) t = i + n - b[i] + 1;
    {
      if (t > answer) {
        flag = 1;
        break;
      }
    }
  }
  if (flag == 0)
    cout << answer << endl;
  else {
    answer = n;
    for (int i = 1; i <= n; i++) {
      if (b[i] > 0) answer = max(answer, i + n - b[i] + 1);
    }
    cout << answer << endl;
  }
  return 0;
}
