#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
using namespace std;
const long long INF = 2e9, INFLL = 1e18, MOD = 1e9 + 7;
vector<long long> t;
void update(long long x, long long xend, long long nod, long long pos,
            long long val) {
  if (x > pos or xend < pos) return;
  if (x == xend) {
    t[nod] = val;
    return;
  }
  long long mid = (x + xend) >> 1;
  update(x, mid, nod * 2, pos, val);
  update(mid + 1, xend, nod * 2 + 1, pos, val);
  t[nod] = min(t[nod * 2], t[nod * 2 + 1]);
}
long long query(long long x, long long xend, long long nod, long long pos) {
  if (x == xend) return x;
  long long mid = (x + xend) >> 1;
  if (t[nod * 2] < pos) return query(x, mid, nod * 2, pos);
  return query(mid + 1, xend, nod * 2 + 1, pos);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n;
  cin >> n;
  t.resize(4 * n);
  vector<long long> ar(n + 1);
  for (long long i = 1; i <= n; i++) cin >> ar[i];
  vector<bool> flag(n + 4);
  vector<long long> last(n + 4);
  for (long long i = 1; i <= n; i++) {
    if (last[ar[i]] + 1 < i) flag[query(1, n + 1, 1, last[ar[i]] + 1)] = true;
    update(1, n + 1, 1, ar[i], i);
    last[ar[i]] = i;
  }
  flag[query(1, n + 1, 1, 1)] = true;
  for (long long i = 1; i <= n; i++)
    if (last[ar[i]] + 1 < n) flag[query(1, n + 1, 1, last[ar[i]] + 1)] = true;
  for (long long i = 1;; i++)
    if (!flag[i]) {
      cout << i;
      break;
    }
  return 0;
}
