#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long int M = 1000000007;
long long int inv(long long int a, long long int b) {
  return 1 < a ? b - inv(b % a, a) * b / a : 1;
}
pair<long long int, long long int> neigh[4] = {
    {-1, 0}, {1, 0}, {0, 1}, {0, -1}};
namespace seg {
long long int id = LLONG_MAX;
long long int f(long long int a, long long int b) { return min(a, b); }
long long int t[2 * 100100];
long long int n = 100100;
void modify(long long int p, long long int value) {
  for (p += n, t[p] = value; p /= 2;) t[p] = f(t[2 * p], t[2 * p + 1]);
}
long long int query(long long int l, long long int r) {
  long long int resl = id, resr = id;
  for (l += n, r += n; l < r; l /= 2, r /= 2) {
    if (l & 1) resl = f(resl, t[l++]);
    if (r & 1) resr = f(t[--r], resr);
  }
  return f(resl, resr);
}
}  // namespace seg
long long int binSearch(long long int l, long long int r, long long int l1) {
  if (l == r) return l;
  long long int mid = (l + r) / 2;
  if (seg::query(1, mid + 1) < l1) return binSearch(l, mid, l1);
  return binSearch(mid + 1, r, l1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int n;
  cin >> n;
  vector<long long int> ar(n);
  for (long long int i = 0; i < (n); i++) cin >> ar[i];
  for (long long int i = 1; i < (100100); i++) seg::modify(i, -1);
  long long int last[100100];
  fill(last, last + 100100, -1);
  bool exists[100100];
  fill(exists, exists + 100100, false);
  bool allEqual = true;
  for (long long int i = 0; i < (n); i++)
    if (ar[i] != 1) allEqual = false;
  if (allEqual) {
    cout << 1 << endl;
    return 0;
  }
  for (long long int i = 0; i < (n); i++) {
    exists[ar[i]] =
        exists[ar[i]] || binSearch(1, 100100, last[ar[i]] + 1) == ar[i];
    seg::modify(ar[i], i);
    last[ar[i]] = i;
  }
  for (long long int i = 1; i < (100100); i++) {
    exists[i] = exists[i] || binSearch(1, 100100, last[i] + 1) == i;
  }
  for (long long int i = 1; i < (100100); i++) {
    if (!exists[i]) {
      cout << i << endl;
      return 0;
    }
  }
}
