#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const double pi = acos(-1);
const double eps = 1e-5;
const int INF = 0x3f3f3f3f;
const long long int INFLL = 0x3f3f3f3f3f3f3f3f;
const int maxn = 100010;
struct STtree {
  struct tree {
    int a;
    int l, r;
    int tag;
    tree() : tag(0), l(0), r(0), a(0) {}
  } node[maxn << 2];
  STtree() {}
  STtree(int l, int r, int* a) { build(1, l, r, a); }
  inline void push_up(int x) {
    node[x].a = min(node[x << 1].a, node[x << 1 | 1].a);
  }
  inline int cmp(int a, int b) { return (a < b ? a : b); }
  void build(int x, int l, int r, int* a) {
    node[x].l = l;
    node[x].r = r;
    node[x].tag = 0;
    if (l == r) {
      if (!a)
        node[x].a = 0;
      else
        node[x].a = a[l];
      return;
    }
    int mid = (l + r) >> 1;
    build(x << 1, l, mid, a);
    build(x << 1 | 1, mid + 1, r, a);
    push_up(x);
  }
  void update(int left, int right, int x, int k) {
    if (left <= node[x].l && node[x].r <= right) {
      node[x].a = k;
      return;
    }
    int mid = (node[x].l + node[x].r) >> 1;
    if (left <= mid) update(left, right, x << 1, k);
    if (right > mid) update(left, right, x << 1 | 1, k);
    push_up(x);
  }
  int query(int left, int right, int x) {
    if (left > right) return 0;
    int res = 0x3f3f3f3f;
    if (left <= node[x].l && node[x].r <= right) return node[x].a;
    int mid = (node[x].l + node[x].r) >> 1;
    if (left <= mid) res = cmp(res, query(left, right, x << 1));
    if (right > mid) res = cmp(res, query(left, right, x << 1 | 1));
    return res;
  }
} st;
int a[maxn];
bool f[maxn];
int p[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];
    if (a[i] > 1) f[1] = true;
  }
  st.build(1, 1, n, 0);
  for (int i = (1); i <= (n); i++) {
    if (st.query(1, a[i] - 1, 1) > p[a[i]]) f[a[i]] = true;
    st.update(a[i], a[i], 1, i);
    p[a[i]] = i;
  }
  int ans = n + 2;
  for (int i = (1); i <= (n + 1); i++) {
    if (f[i]) continue;
    if (st.query(1, i - 1, 1) > p[i]) continue;
    ans = i;
    break;
  }
  cout << ans;
}
