#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
struct Tree {
  int val[maxn << 2];
  void update(int rt, int l, int r, int pos, int v) {
    if (l == r) {
      val[rt] = v;
      return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)
      update(rt << 1, l, mid, pos, v);
    else
      update(rt << 1 | 1, mid + 1, r, pos, v);
    val[rt] = min(val[rt << 1], val[rt << 1 | 1]);
  }
  int query(int rt, int l, int r, int ql, int qr) {
    if (l == ql && r == qr) return val[rt];
    int mid = (l + r) >> 1;
    if (qr <= mid) return query(rt << 1, l, mid, ql, qr);
    if (ql >= mid + 1) return query(rt << 1 | 1, mid + 1, r, ql, qr);
    return min(query(rt << 1, l, mid, ql, mid),
               query(rt << 1 | 1, mid + 1, r, mid + 1, qr));
  }
} T;
int a[maxn], last[maxn];
bool able[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    if (a[i] > 1) able[1] = true;
    if (a[i] > 1 && T.query(1, 1, n, 1, a[i] - 1) > last[a[i]])
      able[a[i]] = true;
    last[a[i]] = i;
    T.update(1, 1, n, a[i], i);
  }
  for (int i = 2; i <= n + 1; i++)
    if (T.query(1, 1, n, 1, i - 1) > last[i]) able[i] = true;
  int ans = 1;
  for (; able[ans]; ans++)
    ;
  cout << ans;
  return 0;
}
