#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long MAXN = 1e5 + 5;
const long long MAXM = 3e5 + 5;
struct Query {
  long long ql, qr, id;
  long long mex;
  void read(long long _id, long long l, long long r) {
    ql = l;
    qr = r;
    id = _id;
  }
} qry[MAXM];
bool cmp_l(const Query &a, const Query &b) { return a.ql < b.ql; }
bool cmp_id(const Query &a, const Query &b) { return a.id < b.id; }
long long vis[MAXN], init_mex[MAXN], next_idx[MAXN];
struct IntervalTree {
  long long lb, rb, size, min_tag;
  IntervalTree *lc, *rc;
  IntervalTree() : min_tag(INF), lc(NULL), rc(NULL) {}
  void push() {
    if (lb == rb) return;
    if (min_tag == INF) return;
    if (lc) lc->min_tag = min(lc->min_tag, min_tag);
    if (rc) rc->min_tag = min(rc->min_tag, min_tag);
    min_tag = INF;
  }
} * root;
void build(IntervalTree *t, long long lb, long long rb) {
  t->lb = lb, t->rb = rb, t->size = rb - lb + 1;
  if (lb == rb) {
    t->min_tag = init_mex[lb];
    return;
  }
  long long mid = (lb + rb) / 2;
  t->lc = new IntervalTree();
  t->rc = new IntervalTree();
  build(t->lc, lb, mid);
  build(t->rc, mid + 1, rb);
}
void update(IntervalTree *t, long long ql, long long qr, long long v) {
  if (qr < t->lb || t->rb < ql) return;
  if (ql <= t->lb && t->rb <= qr) {
    t->min_tag = min(t->min_tag, v);
    return;
  }
  t->push();
  update(t->lc, ql, qr, v);
  update(t->rc, ql, qr, v);
}
long long query(IntervalTree *t, long long k) {
  if (t->lb == t->rb) return t->min_tag;
  t->push();
  long long mid = (t->lb + t->rb) / 2;
  if (k <= mid) return query(t->lc, k);
  return query(t->rc, k);
}
long long n, m;
long long a[MAXN];
void init() {
  memset(vis, -1, sizeof(vis));
  for (long long i = n - 1; i >= 0; --i) next_idx[i] = vis[a[i]], vis[a[i]] = i;
  memset(vis, 0, sizeof(vis));
  long long cur_mex = 0;
  for (long long i = 0; i < n; ++i) {
    if (a[i] < MAXN) vis[a[i]] = 1;
    while (vis[cur_mex]) ++cur_mex;
    init_mex[i] = cur_mex;
  }
  root = new IntervalTree();
  build(root, 0, n - 1);
}
void solve() {
  init();
  sort(qry, qry + m, cmp_l);
  long long l = 0;
  for (long long i = 0; i < m; ++i) {
    while (l < qry[i].ql) {
      long long nxt = next_idx[l];
      if (nxt < 0) nxt = MAXN;
      if (l + 1 <= nxt - 1) update(root, l + 1, nxt - 1, a[l]);
      ++l;
    }
    qry[i].mex = query(root, qry[i].qr);
  }
  sort(qry, qry + m, cmp_id);
}
vector<long long> pos[MAXN];
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; ++i) pos[i].push_back(-1);
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    pos[a[i]].push_back(i);
    --a[i];
  }
  for (long long i = 1; i <= n; ++i) pos[i].push_back(n);
  vector<long long> sol(n + 5, 0);
  vector<pair<long long, long long> > cnt(n + 5);
  for (long long x = 1; x <= n; ++x) {
    cnt[x].first = m;
    for (long long j = 1; j < pos[x].size(); ++j) {
      if (pos[x][j - 1] == pos[x][j] - 1) continue;
      qry[m++].read(m - 1, pos[x][j - 1] + 1, pos[x][j] - 1);
    }
    cnt[x].second = m - 1;
  }
  qry[m++].read(m - 1, 0ll, n - 1);
  solve();
  for (long long x = 1; x <= n; ++x) {
    bool ok = 0;
    for (long long j = cnt[x].first; j <= cnt[x].second; ++j) {
      if (qry[j].mex == x - 1) {
        ok = 1;
        break;
      }
    }
    if (ok) sol[x] = 1;
  }
  if (qry[m - 1].mex == n) sol[n + 1] = 1;
  for (long long i = 1; i <= n + 2; ++i) {
    if (!sol[i]) return cout << i << '\n', 0;
  }
  return 0;
}
