#include <bits/stdc++.h>
using i32 = int;
using i64 = long long;
i32 main() {
  std::ios::sync_with_stdio(false);
  std::cout.tie(nullptr);
  std::cin.tie(nullptr);
  i32 n;
  std::cin >> n;
  std::vector<i32> a(n);
  for (i32 i = 0; i < n; i++) {
    std::cin >> a[i];
    --a[i];
  }
  std::vector<std::vector<i32>> p(n, std::vector<i32>(1, -1));
  for (i32 i = 0; i < n; i++) p[a[i]].push_back(i);
  for (i32 i = 0; i < n; i++) p[i].push_back(n);
  struct Node {
    i32 minimum, left, right;
  };
  std::vector<Node> tree(1, {-1, 0, 0});
  auto make_node = [&](i32 x) {
    i32 id = tree.size();
    tree.push_back({x, 0, 0});
    return id;
  };
  auto merge = [&](i32 left, i32 right) {
    i32 id = tree.size();
    i32 minimum = std::min(tree[left].minimum, tree[right].minimum);
    tree.push_back({minimum, left, right});
    return id;
  };
  auto left_child = [&](i32 i) -> Node& { return tree[tree[i].left]; };
  auto update = [&](i32 root, i32 p, i32 x) {
    std::function<i32(i32, i32, i32)> dfs;
    dfs = [&](i32 i, i32 l, i32 r) {
      if (p < l || r <= p) return i;
      if (l + 1 == r) return make_node(x);
      i32 m = (l + r) / 2;
      return merge(dfs(tree[i].left, l, m), dfs(tree[i].right, m, r));
    };
    return dfs(root, 0, n + 1);
  };
  auto mex = [&](i32 i, i32 x) {
    i32 l = 0, r = n + 1;
    while (l + 1 != r) {
      i32 m = (l + r) / 2;
      if (left_child(i).minimum < x) {
        i = tree[i].left;
        r = m;
      } else {
        i = tree[i].right;
        l = m;
      }
    }
    return l;
  };
  std::vector<i32> root(n + 1);
  for (i32 i = 0; i < n; i++) root[i + 1] = update(root[i], a[i], i);
  std::vector<bool> good(n + 2, false);
  good[mex(root[n], 0)] = true;
  for (i32 i = 0; i < n; i++) {
    for (i32 j = 1; j < p[i].size(); j++) {
      if (p[i][j - 1] + 1 != p[i][j])
        good[mex(root[p[i][j]], p[i][j - 1] + 1)] = true;
    }
  }
  std::cout << std::find(good.begin(), good.end(), false) - good.begin() + 1
            << "\n";
  return 0;
}
