#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int vis[maxn];
int n, x;
int a[maxn];
bool v[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    vis[x] = 0;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    a[i] = x;
    vis[x] = i;
  }
  int cnt = 1;
  int flag = 1;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) {
      for (int j = i; j <= n; j++) {
        if (a[j] == cnt) {
          cnt++;
        } else {
          flag = 0;
          break;
        }
      }
    }
  }
  int cz = 0;
  if (flag) {
    while (cnt <= n) {
      if (vis[cnt] == 0) {
        cnt++;
        cz++;
        continue;
      }
      if (vis[cnt] <= cz) {
        cz++;
        cnt++;
      } else
        break;
    }
    if (cnt > n) {
      printf("%d", cz);
      return 0;
    }
  }
  vis[0] = 1;
  for (int i = 1; i <= n; i++) {
    if (!v[i]) vis[i] = max(vis[i], vis[i - 1]) + 1;
  }
  printf("%d", vis[n]);
  return 0;
}
