#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 2e5 + 5;
int n, a[N], last[N];
int t[N * 4], b[N];
void upd(int I, int V, int i = 1, int l = 1, int r = N - 1) {
  if (r < I || l > I) return;
  if (l == r) return void(t[i] = V);
  int m = (l + r) / 2;
  upd(I, V, i * 2, l, m);
  upd(I, V, i * 2 + 1, m + 1, r);
  t[i] = min(t[i * 2], t[i * 2 + 1]);
}
int que(int L, int R, int i = 1, int l = 1, int r = N - 1) {
  if (r < L || l > R || L > R) return INT_MAX;
  if (L <= l && r <= R) return t[i];
  int m = (l + r) / 2;
  return min(que(L, R, i * 2, l, m), que(L, R, i * 2 + 1, m + 1, r));
}
int32_t main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (last[a[i]] + 1 < i && que(1, a[i] - 1) > last[a[i]]) b[a[i]] = 1;
    last[a[i]] = i;
    upd(a[i], i);
  }
  for (int i = 1; i < N; i++) {
    if (last[i] != n && que(1, i - 1) > last[i]) b[i] = 1;
    if (!b[i]) return cout << i, 0;
  }
}
