#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using dd = double;
using vi = vector<int>;
template <class T, class V>
std::istream& operator>>(std::istream& in, std::pair<T, V>& pair) {
  return in >> pair.first >> pair.second;
}
template <class T>
std::istream& operator>>(std::istream& in, std::vector<T>& elements) {
  for (size_t i = 0; i < elements.size(); ++i) {
    in >> elements[i];
  }
  return in;
}
template <class Container, class Element>
bool Contains(const Container& container, const Element& element) {
  return container.find(element) != container.end();
}
template <class T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& elements) {
  for (const T& element : elements) {
    out << element << ' ';
  }
  return out;
}
int GetZeroCount(const vi& v) {
  int c = 0;
  for (int el : v) {
    c += (el == 0);
  }
  return c;
}
set<int> GetNotEmptyCards(const vi& a) {
  set<int> r;
  for (int el : a) {
    if (el != 0) {
      r.insert(el);
    }
  }
  return r;
}
int NeededCard(const vi& b) {
  int ans = b.back();
  for (int i = b.size() - 2; i >= 0 && i >= b.size() - ans; i--) {
    if (b[i] + 1 != b[i + 1]) {
      return 1;
    }
  }
  return ans + 1;
}
bool Check(int add_zeros, int zero_count, set<int> cards, const vi& b,
           int& ans) {
  zero_count -= add_zeros;
  for (int i = 0; i < add_zeros; ++i) {
    if (b[i] == 0) {
      ++zero_count;
    } else {
      cards.insert(b[i]);
    }
  }
  int needed_card = 1;
  for (int i = add_zeros; i < b.size(); ++i) {
    if (!Contains(cards, needed_card)) {
      return false;
    }
    ++needed_card;
    if (b[i] != 0) {
      cards.insert(b[i]);
    }
  }
  return true;
}
bool CheckZero(set<int> cards, const vi& b, int* ans) {
  int needed_card = NeededCard(b);
  *ans = (int)(b.size() + 1 - needed_card);
  for (int i = 0; i < b.size(); ++i) {
    if (needed_card == b.size() + 1) {
      break;
    }
    if (!Contains(cards, needed_card)) {
      return false;
    }
    ++needed_card;
    if (b[i] != 0) {
      cards.insert(b[i]);
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vi a(n), b(n);
  cin >> a >> b;
  int zero_count = GetZeroCount(a);
  set<int> cards = GetNotEmptyCards(a);
  int ans;
  if (CheckZero(cards, b, &ans)) {
    cout << ans << endl;
    return 0;
  }
  int l = 1, r = n;
  while (l < r) {
    int m = (r + l) / 2;
    if (Check(m, zero_count, cards, b, ans)) {
      r = m;
    } else {
      l = m + 1;
    }
  }
  cout << l + n << endl;
  return 0;
}
