#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 100005;
int n;
int a[N_MAX];
vector<int> v[N_MAX];
struct SGTNode {
  int maxVal;
  int lazy;
};
SGTNode SGT[N_MAX * 4];
void split(int node) {
  int lSon = (node << 1), rSon = (lSon | 1);
  SGT[lSon].maxVal = max(SGT[lSon].maxVal, SGT[node].lazy);
  SGT[rSon].maxVal = max(SGT[rSon].maxVal, SGT[node].lazy);
  SGT[lSon].lazy = max(SGT[lSon].lazy, SGT[node].lazy);
  SGT[rSon].lazy = max(SGT[rSon].lazy, SGT[node].lazy);
  SGT[node].lazy = 0;
}
void build(int node, int l, int r) {
  if (l == r) {
    SGT[node].maxVal = l;
    SGT[node].lazy = 0;
    return;
  }
  int mid = ((l + r) >> 1), lSon = (node << 1), rSon = (lSon | 1);
  build(lSon, l, mid);
  build(rSon, mid + 1, r);
  SGT[node].maxVal = max(SGT[lSon].maxVal, SGT[rSon].maxVal);
}
void update(int node, int l, int r, int ul, int ur, int uval) {
  if (ul <= l && r <= ur) {
    SGT[node].maxVal = max(SGT[node].maxVal, uval);
    SGT[node].lazy = max(SGT[node].lazy, uval);
    return;
  }
  split(node);
  int mid = ((l + r) >> 1), lSon = (node << 1), rSon = (lSon | 1);
  if (ul <= mid) update(lSon, l, mid, ul, ur, uval);
  if (mid + 1 <= ur) update(rSon, mid + 1, r, ul, ur, uval);
  SGT[node].maxVal = max(SGT[lSon].maxVal, SGT[rSon].maxVal);
}
int query(int node, int l, int r, int qpos) {
  if (l == r) return SGT[node].maxVal;
  split(node);
  int mid = ((l + r) >> 1), lSon = (node << 1), rSon = (lSon | 1);
  if (qpos <= mid)
    return query(lSon, l, mid, qpos);
  else
    return query(rSon, mid + 1, r, qpos);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n + 1; i++) v[i].push_back(0);
  for (int i = 1; i <= n; i++) v[a[i]].push_back(i);
  for (int i = 1; i <= n + 1; i++) v[i].push_back(n + 1);
  build(1, 1, n);
  for (int i = 1; i <= n + 1; i++) {
    for (int j = 1; j < (int)v[i - 1].size(); j++)
      if (v[i - 1][j - 1] + 1 <= v[i - 1][j] - 1)
        update(1, 1, n, v[i - 1][j - 1] + 1, v[i - 1][j] - 1, v[i - 1][j]);
    bool ok = false;
    for (int j = 1; j < (int)v[i].size(); j++)
      if (v[i][j - 1] + 1 <= v[i][j] - 1)
        ok |= (query(1, 1, n, v[i][j - 1] + 1) < v[i][j]);
    if (ok == false) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << n + 2 << "\n";
  return 0;
}
