#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, x, last[N * 2], t[N * 4];
bool mp[N];
void insert(int v, int tl, int tr, int pos, int val) {
  if (tl == tr)
    t[v] = val;
  else {
    int mid = (tl + tr) / 2;
    if (pos <= mid)
      insert(v * 2, tl, mid, pos, val);
    else
      insert(v * 2 + 1, mid + 1, tr, pos, val);
    t[v] = min(t[v * 2], t[v * 2 + 1]);
  }
}
int find(int v, int tl, int tr, int k) {
  if (tl == tr)
    return tl;
  else {
    int mid = (tl + tr) / 2;
    if (t[v * 2] < k)
      return find(v * 2, tl, mid, k);
    else
      return find(v * 2 + 1, mid + 1, tr, k);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (last[x] + 1 < i) mp[find(1, 1, N, last[x] + 1)] = 1;
    insert(1, 1, N, x, i);
    last[x] = i;
  }
  for (int i = 1; i <= N; i++) {
    if (last[i] && last[i] != n) {
      mp[find(1, 1, N, last[i] + 1)] = 1;
    }
  }
  mp[find(1, 1, N, 1)] = 1;
  for (int i = 1;; i++)
    if (!mp[i]) {
      printf("%d", i);
      break;
    }
  return 0;
}
