#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 4;
int solve() {
  int n;
  scanf("%d", &n);
  int a[n + 1], b[n + 1];
  map<int, int> ma;
  for (int i = 1; i < n + 1; i++) scanf("%d", &a[i]), ma[a[i]] = 0;
  for (int i = 1; i < n + 1; i++) scanf("%d", &b[i]), ma[b[i]] = i;
  int ans = 0;
  if (b[n] != 0) {
    int flag = 1, ind = n, want = b[n];
    while (want >= 1) {
      if (b[ind] == want)
        ind--, want--;
      else {
        flag = 0;
        break;
      }
    }
    int tim = 0;
    if (flag) {
      for (int i = b[n] + 1; i < n + 1; i++) {
        if (ma[i] > tim)
          flag = 0;
        else
          tim++;
      }
    }
    if (flag) {
      printf("%d", tim);
      return 0;
    }
  }
  for (int i = 1; i < n + 1; i++) ans = max(ans, n + ma[i] - (i - 1));
  printf("%d", ans);
  return 0;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
