#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int mod = 998244353;
int x[N], y[N], pos[N];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    if (x[i]) pos[x[i]] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> y[i];
    if (y[i]) pos[y[i]] = max(i + 1, 0);
  }
  bool w = true;
  int c = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (y[i] - y[i - 1] == 1 && y[i - 1] != 0)
      c++;
    else if (y[i] - y[i - 1] == 1) {
      c++;
      break;
    } else if (y[i] == 1) {
      c++;
      break;
    } else
      w = false;
    if (i == 0) w = false;
  }
  if (w) {
    if (c == n) {
      cout << 0 << endl;
      return 0;
    } else {
      bool nw = true;
      for (int i = c + 1; i <= n; i++) {
        if (pos[i] > i - c - 1) break;
        if (i == n) nw = false;
      }
      if (!nw) {
        cout << n - c << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (y[i]) pos[y[i]] = max(i + 1 - y[i] + 1, 0);
  }
  sort(pos + 1, pos + n + 1);
  cout << n + pos[n] << endl;
}
