#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int block = 320;
struct Query {
  int L, R, idx;
};
Query q[N];
int a[N], fre[N], blk[N];
bool compare(Query x, Query y) {
  if (x.L / block != y.L / block) return x.L / block < y.L / block;
  return x.R < y.R;
}
void add(int i) {
  fre[a[i]]++;
  if (fre[a[i]] == 1) blk[a[i] / block]++;
}
void rem(int i) {
  fre[a[i]]--;
  if (fre[a[i]] == 0) blk[a[i] / block]--;
}
int mex() {
  for (int i = 0;; i++) {
    if (blk[i] < block) {
      for (int j = i * block;; j++) {
        if (fre[j] == 0) return j;
      }
    }
  }
}
void solve() {
  int n, m;
  cin >> n;
  vector<int> v[n + 3];
  for (int i = 0; i < n + 2; i++) v[i].push_back(-1);
  for (int i = 0, x; i < n; i++) {
    cin >> x;
    a[i] = x;
    a[i]--;
    v[a[i]].push_back(i);
  }
  for (int i = 0; i < n + 2; i++) v[i].push_back(n);
  vector<pair<int, int> > q1;
  for (int i = 0; i < n + 2; i++) {
    for (int j = 1; j < v[i].size(); j++) {
      int left = v[i][j - 1] + 1;
      int right = v[i][j] - 1;
      if (left <= right) q1.push_back({left, right});
    }
  }
  m = q1.size();
  int final[m];
  for (int i = 0; i < m; i++) {
    q[i].L = q1[i].first;
    q[i].R = q1[i].second;
    q[i].idx = i;
  }
  sort(q, q + m, compare);
  int currL = 0, currR = 0;
  int currSum = 0;
  for (int i = 0; i < m; i++) {
    int L = q[i].L, R = q[i].R;
    while (currL < L) {
      rem(currL);
      currL++;
    }
    while (currL > L) {
      add(currL - 1);
      currL--;
    }
    while (currR <= R) {
      add(currR);
      currR++;
    }
    while (currR > R + 1) {
      rem(currR - 1);
      currR--;
    }
    final[q[i].idx] = mex();
  }
  int k = 0;
  for (int i = 0; i < n + 2; i++) {
    int chk = 0;
    for (int j = 1; j < v[i].size(); j++) {
      int left = v[i][j - 1] + 1;
      int right = v[i][j] - 1;
      if (left <= right) {
        if (final[k] == i) {
          chk = 1;
        }
        k++;
      }
    }
    if (!chk) {
      cout << i + 1;
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}
