#include <bits/stdc++.h>
using namespace std;
const int inv = 1000000000;
const int minv = -inv;
const int max_n = 100000 + 5;
int slr[4 * max_n + 10];
int srr[4 * max_n + 10];
int sq[4 * max_n + 10];
struct ST {
  int sn;
  ST() { sn = 0; }
  ST(int sn_) {
    sn = sn_;
    init(0, 0, sn);
  }
  void init(int ix, int l, int r) {
    slr[ix] = l;
    srr[ix] = r;
    sq[ix] = -1;
    if (l + 1 < r) {
      int mid = (l + r) / 2;
      init(2 * ix + 1, l, mid);
      init(2 * ix + 2, mid, r);
    }
  }
  void pupdate(int ix, int pos, int val) {
    int lc = 2 * ix + 1, rc = 2 * ix + 2;
    if (slr[ix] + 1 == srr[ix]) {
      sq[ix] = val;
      return;
    }
    if (pos < srr[lc])
      pupdate(lc, pos, val);
    else
      pupdate(rc, pos, val);
    sq[ix] = min(sq[lc], sq[rc]);
  }
  void update(int pos, int val) { pupdate(0, pos, val); }
  int iquery(int ix, int l, int r) {
    int lc = 2 * ix + 1;
    int rc = 2 * ix + 2;
    if (l == slr[ix] and r == srr[ix])
      return sq[ix];
    else if (r <= srr[lc])
      return iquery(lc, l, r);
    else if (l >= slr[rc])
      return iquery(rc, l, r);
    else
      return min(iquery(lc, l, srr[lc]), iquery(rc, slr[rc], r));
  }
  int query(int l, int r) { return iquery(0, l, r + 1); }
};
ST st;
int n;
int a[max_n];
bool all_zeroes;
int locc[max_n + 1];
bool mark[max_n + 1];
int res = 1;
int main() {
  scanf("%d", &n);
  all_zeroes = true;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    --a[i];
    all_zeroes = (all_zeroes and a[i] == 0);
  }
  if (all_zeroes) {
    printf("%d\n", 1);
    return 0;
  }
  fill(locc, locc + n + 1, -1);
  fill(mark, mark + n + 1, false);
  mark[0] = true;
  st = ST(n + 1);
  for (int i = 0; i < n; ++i) {
    if (a[i] > 0 and st.query(0, a[i] - 1) > locc[a[i]]) mark[a[i]] = true;
    locc[a[i]] = i;
    st.update(a[i], i);
  }
  for (int j = 1; j < n + 1; ++j)
    if (st.query(0, j - 1) > locc[j]) mark[j] = true;
  for (int j = 1; j < n + 1; ++j)
    if (not mark[j]) {
      printf("%d\n", j + 1);
      return 0;
    }
  printf("%d\n", n + 2);
  return 0;
}
