#include <bits/stdc++.h>
using namespace std;
template <typename first, typename second>
ostream &operator<<(ostream &os, const pair<first, second> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  typename vector<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  os << "[";
  typename set<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename first, typename second>
ostream &operator<<(ostream &os, const map<first, second> &v) {
  os << "[";
  typename map<first, second>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << it->first << " = " << it->second;
  }
  return os << "]";
}
long long n;
vector<long long> a;
vector<long long> b;
vector<long long> pos;
bool check() {
  if (pos[1] == -1) {
    for (long long i = 2; i <= n; i++) {
      long long rem;
      if (pos[i] == -1) {
        rem = 1;
      } else {
        rem = pos[i] + 2;
      }
      if (rem <= (i)) {
      } else {
        return false;
      }
    }
  } else {
    long long las = b[n - 1];
    for (long long i = b[n - 1] + 1; i <= n; i++) {
      long long rem;
      if (pos[i] == -1) {
        rem = 1;
      } else {
        rem = pos[i] + 2;
      }
      if (rem <= (i - (b[n - 1]))) {
      } else {
        return false;
      }
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin >> n;
  a.resize(n);
  b.resize(n);
  pos.resize(n + 1);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] != 0) {
      pos[a[i]] = -1;
    }
  }
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] != 0) {
      pos[b[i]] = i;
    }
  }
  long long mvs = 0;
  long long f = 0;
  for (long long i = 0; i < n; i++) {
    if (b[i] == i + 1) {
    } else {
      f = 1;
    }
  }
  if (f == 0) {
    cout << mvs << "\n";
    return 0;
  }
  if (pos[1] != -1) {
    long long f = 1;
    for (long long i = pos[1] + 1; i < n; i++) {
      if (b[i] != i - pos[1] + 1) {
        f = 0;
      }
    }
    if (f == 1) {
      if (check()) {
        if (pos[1] == -1) {
          cout << n << "\n";
        } else {
          cout << (n - b[n - 1]) << "\n";
        }
      } else {
        if (pos[1] != -1) {
          long long I;
          for (long long i = 0; i < n; i++) {
            if (b[i] == 1) {
              pos[1] = -1;
              mvs++;
              I = i;
              break;
            } else {
              if (b[i] != 0) {
                pos[b[i]] = -1;
                mvs++;
              } else {
                mvs++;
              }
            }
          }
          long long ct = 0;
          for (long long i = I + 1; i < n; i++) {
            if (b[i] != 0) {
              pos[b[i]] = ct;
              ct++;
            } else {
              ct++;
            }
          }
        }
        if (check()) {
          cout << (mvs + n) << "\n";
        } else {
          long long I;
          long long req = -1;
          for (long long i = n - 1; i >= 0; i--) {
            if (b[i] != 0) {
              long long rem = i + 2;
              if (rem > b[i]) {
                I = i;
                req = max(req, rem - b[i]);
              }
            }
          }
          cout << (mvs + req + n) << "\n";
        }
      }
    } else {
      if (pos[1] != -1) {
        long long I;
        for (long long i = 0; i < n; i++) {
          if (b[i] == 1) {
            pos[1] = -1;
            mvs++;
            I = i;
            break;
          } else {
            if (b[i] != 0) {
              pos[b[i]] = -1;
              mvs++;
            } else {
              mvs++;
            }
          }
        }
        long long ct = 0;
        for (long long i = I + 1; i < n; i++) {
          if (b[i] != 0) {
            pos[b[i]] = ct;
            ct++;
          } else {
            ct++;
          }
        }
      }
      long long I;
      long long req = 0;
      for (long long i = n - 1; i >= 0; i--) {
        if (b[i] != 0) {
          long long rem = pos[b[i]] + 2;
          if (rem > b[i]) {
            I = i;
            req = max(req, rem - b[i]);
          }
        }
      }
      cout << (mvs + n + req) << "\n";
    }
  } else {
    long long I;
    long long req = 0;
    for (long long i = n - 1; i >= 0; i--) {
      if (b[i] != 0) {
        long long rem = pos[b[i]] + 2;
        if (rem > b[i]) {
          I = i;
          req = max(req, rem - b[i]);
        }
      }
    }
    cout << (n + req) << "\n";
  }
  return 0;
}
