#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 5;
const double eps = 1e-4;
const int mod = 1e9 + 7;
int a[N];
int b[N], pos[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pos[a[i]] = 0;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    pos[b[i]] = i;
  }
  int la = 0;
  if (pos[1]) {
    int f = 0;
    for (int i = pos[1] + 1; i <= n; i++) {
      if (b[i] - b[i - 1] != 1) {
        f = 1;
        break;
      }
    }
    if (!f) {
      int tep = b[n];
      int ans = 0;
      int v = 0;
      for (int i = b[n] + 1; i <= n; i++) {
        if (pos[i] == 0)
          ans++;
        else if (pos[i] - ans <= 0) {
          ans++;
        } else {
          v = 1;
          break;
        }
      }
      if (!v) {
        printf("%d\n", ans);
        return 0;
      }
    }
  }
  int v = 0;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, pos[i] - i + 1 + n);
  }
  printf("%d\n", ans);
  return 0;
}
