#include <bits/stdc++.h>
using namespace std;
const int INF = (int)(1e9 + 7);
struct Vertex {
  Vertex *l, *r;
  long long mini;
  Vertex(long long val) : l(nullptr), r(nullptr), mini(val) {}
  Vertex(Vertex* l, Vertex* r) : l(l), r(r), mini(INF) {
    if (l) mini = min(mini, l->mini);
    if (r) mini = min(mini, r->mini);
  }
};
Vertex* build(vector<long long>& a, long long tl, long long tr) {
  if (tl == tr) return new Vertex(a[tl]);
  long long tm = (tl + tr) / 2;
  return new Vertex(build(a, tl, tm), build(a, tm + 1, tr));
}
long long get_min(Vertex* v, long long tl, long long tr, long long l,
                  long long r) {
  if (l > r) return INF;
  if (l == tl && tr == r) return v->mini;
  long long tm = (tl + tr) / 2;
  return min(get_min(v->l, tl, tm, l, min(r, tm)),
             get_min(v->r, tm + 1, tr, max(l, tm + 1), r));
}
Vertex* update(Vertex* v, long long tl, long long tr, long long pos,
               long long new_val) {
  if (tl == tr) return new Vertex(new_val);
  long long tm = (tl + tr) / 2;
  if (pos <= tm)
    return new Vertex(update(v->l, tl, tm, pos, new_val), v->r);
  else
    return new Vertex(v->l, update(v->r, tm + 1, tr, pos, new_val));
}
vector<Vertex*> estado;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  vector<vector<int> > lista(n + 5);
  for (long long i = (0); i < (long long)(n + 5); i++) lista[i].push_back(-1);
  for (long long i = (0); i < (long long)(n); i++) {
    cin >> v[i];
    lista[v[i]].push_back(i);
  }
  for (long long i = (0); i < (long long)(n + 5); i++) lista[i].push_back(n);
  vector<long long> last(n + 5, -1);
  estado.push_back(build(last, 0, n + 5));
  for (long long i = (0); i < (long long)(n); i++) {
    estado.push_back(update(estado.back(), 0, n + 5, v[i], i));
  }
  for (long long ans = (1); ans < (long long)(n + 5); ans++) {
    bool d = true;
    int l = 0;
    for (int u : lista[ans]) {
      if (u - 1 < l) {
        l = u + 1;
        continue;
      }
      int aux = get_min(estado[u], 0, n + 5, 1, ans - 1);
      if (aux >= l) d = false;
      l = u + 1;
    }
    if (d == true) {
      cout << ans << "\n";
      return 0;
    }
  }
  return 0;
}
