#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const long long inf = 5e9 + 7;
const long long max_n = (1 << 17);
struct req {
  long long r, col;
  req() {}
  req(long long r, long long col) : r(r), col(col) {}
};
long long n, a[max_n], mx[2 * max_n];
vector<req> b[max_n];
void build() { fill(mx, mx + 2 * max_n, inf); }
void segset(long long id, long long x, long long v = 1, long long tl = 0,
            long long tr = max_n - 1) {
  if (tl > id || tr < id) return;
  if (tl == id && tr == id) {
    mx[v] = x;
    return;
  }
  long long mid = (tl + tr) / 2;
  segset(id, x, v * 2, tl, mid);
  segset(id, x, v * 2 + 1, mid + 1, tr);
  mx[v] = max(mx[v * 2], mx[v * 2 + 1]);
}
long long segget(long long r, long long v = 1, long long tl = 0,
                 long long tr = max_n - 1) {
  if (tl > r) return -1;
  if (tr <= r) return mx[v];
  long long mid = (tl + tr) / 2;
  return max(segget(r, v * 2, tl, mid), segget(r, v * 2 + 1, mid + 1, tr));
}
void solve() {
  cin >> n;
  vector<long long> lst(n + 1, -1);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
    b[lst[a[i]] + 1].emplace_back(req(i - 1, a[i]));
    lst[a[i]] = i;
  }
  for (long long i = 0; i <= n; i++) b[lst[i] + 1].emplace_back(req(n - 1, i));
  build();
  vector<bool> bad(n + 2);
  for (long long i = n - 1; i >= 0; i--) {
    segset(a[i], i);
    for (auto r : b[i]) {
      if (segget(r.col - 1) <= r.r) bad[r.col] = true;
    }
  }
  bad[0] = false;
  for (long long i = 0; i < n; i++)
    if (a[i] != 0) bad[0] = true;
  for (long long i = 0; i <= n + 1; i++) {
    if (!bad[i]) {
      cout << i + 1 << endl;
      return;
    }
  }
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cout.precision(10);
  solve();
}
