#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, a[N], b[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  int pos1 = -1;
  bool flag = 1;
  for (int i = 0; i < n; i++) {
    if (b[i] == 1) pos1 = i;
    if (pos1 != -1 && (b[i] - 1) != i - pos1) flag = 0;
  }
  if (pos1 != -1 && flag) {
    for (int i = 0; i < pos1; i++) {
      if (b[i]) {
        if (b[i] - b[n - 1] - 1 <= i) flag = 0;
      }
    }
    if (flag) return cout << pos1, 0;
  }
  int ans = n;
  for (int i = 0; i < n; i++) {
    if (b[i] <= i + 1 && b[i]) ans = max(ans, (i + 1) - b[i] + 1 + n);
  }
  cout << ans;
  return 0;
}
