#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, a[N], lst[N];
bool notAns[N];
struct segTree {
  int l, r, id;
} tr[N << 2];
inline void pushup(int id) {
  tr[id].id = min(tr[id << 1].id, tr[id << 1 | 1].id);
}
void build(int id, int l, int r) {
  tr[id].l = l, tr[id].r = r;
  tr[id].id = 0;
  if (l == r) return;
  build(id << 1, l, ((tr[id].l + tr[id].r) >> 1)),
      build(id << 1 | 1, ((tr[id].l + tr[id].r) >> 1) + 1, r);
  pushup(id);
}
void modify(int id, int pos, int val) {
  if (tr[id].l == tr[id].r) {
    tr[id].id = val;
    return;
  }
  if (pos <= ((tr[id].l + tr[id].r) >> 1))
    modify(id << 1, pos, val);
  else
    modify(id << 1 | 1, pos, val);
  pushup(id);
}
int query(int id, int l, int r) {
  if (l > r) return 0;
  if (tr[id].l == l && tr[id].r == r) return tr[id].id;
  if (r <= ((tr[id].l + tr[id].r) >> 1))
    return query(id << 1, l, r);
  else if (l > ((tr[id].l + tr[id].r) >> 1))
    return query(id << 1 | 1, l, r);
  else
    return min(query(id << 1, l, ((tr[id].l + tr[id].r) >> 1)),
               query(id << 1 | 1, ((tr[id].l + tr[id].r) >> 1) + 1, r));
}
int main() {
  scanf("%d", &n);
  build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (query(1, 1, a[i] - 1) > lst[a[i]]) notAns[a[i]] = true;
    if (a[i] == 1 && i - 1 > lst[a[i]]) notAns[a[i]] = true;
    lst[a[i]] = i;
    modify(1, a[i], i);
  }
  for (int i = 1; i <= n + 1; i++) {
    notAns[i] |= (query(1, 1, i - 1) > lst[i]);
    if (i == 1) notAns[i] |= (n > lst[a[i]]);
    if (!notAns[i]) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("%d\n", n + 2);
  return 0;
}
