#include <bits/stdc++.h>
using namespace std;
using ll = int;
const ll maxn = 1e5 + 6, inf = maxn, mod = 1e9 + 7;
ll n, a[maxn], seg[maxn * 4], ans;
vector<ll> v[maxn];
bool mark[maxn], b1, b2;
void fix(ll p, ll x, ll v = 1, ll s = 0, ll e = n + 1) {
  if (e - s == 1) {
    seg[v] = x;
    return;
  }
  ll mid = (e + s) / 2, lc = v + v, rc = lc + 1;
  if (mid > p)
    fix(p, x, lc, s, mid);
  else
    fix(p, x, rc, mid, e);
  seg[v] = min(seg[lc], seg[rc]);
}
ll get(ll l, ll r, ll v = 1, ll s = 0, ll e = n + 1) {
  if (l >= e || r <= s) return inf;
  if (l <= s && e <= r) return seg[v];
  ll mid = (e + s) / 2, lc = v + v, rc = lc + 1;
  return min(get(l, r, lc, s, mid), get(l, r, rc, mid, e));
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  memset(seg, -1, sizeof seg);
  cin >> n;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    v[a[i]].push_back(i);
    fix(a[i] - 1, i);
    if (a[i] == 1) {
      b1 = 1;
      continue;
    } else
      b2 = 1;
    ll m = get(0, a[i] - 1);
    if (m == -1) continue;
    if (v[a[i]].size() == 1)
      mark[a[i]] = 1;
    else if (v[a[i]][v[a[i]].size() - 2] < m)
      mark[a[i]] = 1;
  }
  for (ll i = 2; i <= n + 1; i++) {
    ll m = get(0, i - 1);
    if (m == -1) break;
    if (v[i].size() == 0)
      mark[i] = 1;
    else if (v[i][v[i].size() - 1] < m)
      mark[i] = 1;
  }
  if (!b1) {
    cout << 2 << endl;
    return 0;
  }
  if (!b2) {
    cout << 1 << endl;
    return 0;
  }
  mark[1] = 1;
  ans = 1;
  while (mark[ans]) ans++;
  cout << ans << endl;
}
