#include <bits/stdc++.h>
using namespace std;
const long long dx[] = {0, 1, 0, -1};
const long long dy[] = {1, 0, -1, 0};
const long long inf = 2e6;
const long long mod = 1e9 + 7;
const long long N = 2e6 + 11;
const long long INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);
long long n, a[N], t[4 * N], last[N], ok[N];
vector<long long> g[N];
vector<pair<long long, long long>> Q[N];
vector<pair<long long, pair<long long, long long>>> v;
void update(long long v, long long l, long long r, long long pos,
            long long val) {
  if (l == r) {
    t[v] = val;
    return;
  }
  long long mid = (l + r) >> 1;
  if (pos <= mid)
    update(2 * v, l, mid, pos, val);
  else
    update(2 * v + 1, mid + 1, r, pos, val);
  t[v] = min(t[2 * v], t[2 * v + 1]);
}
long long q(long long v, long long tl, long long tr, long long l, long long r) {
  if (l > tr || tl > r) return INF64;
  if (l <= tl && tr <= r) return t[v];
  long long mid = (tl + tr) >> 1;
  long long ans = min(q(2 * v, tl, mid, l, r), q(2 * v + 1, mid + 1, tr, l, r));
  return ans;
}
void solve() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    g[a[i]].push_back(i);
  }
  for (long long i = 1; i <= n + 1; i++) {
    long long lst = 0;
    for (auto it : g[i]) {
      v.push_back({i, {lst + 1, it - 1}});
      lst = it;
    }
    v.push_back({i, {lst + 1, n}});
  }
  for (auto it : v) {
    long long L = it.second.first;
    long long R = it.second.second;
    if (L > R) continue;
    Q[R].push_back({L, it.first});
  }
  for (long long r = 1; r <= n; r++) {
    last[a[r]] = r;
    update(1, 1, n, a[r], r);
    for (auto it : Q[r]) {
      ok[it.second] |= (q(1, 1, n, 1, it.second - 1) >= it.first);
    }
  }
  long long ans = 1;
  while (ok[ans]) ans++;
  cout << ans << '\n';
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long T = 1;
  while (T--) {
    solve();
  }
}
