#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n;
int a[maxn], able[maxn];
int last[maxn];
struct node {
  int l, r, val;
} t[maxn << 2];
void build(int root, int l, int r) {
  t[root].l = l, t[root].r = r;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(root << 1, l, mid);
  build(root << 1 | 1, mid + 1, r);
}
void update(int root, int pos, int x) {
  if (t[root].l == t[root].r) {
    t[root].val = x;
    return;
  }
  int mid = (t[root].l + t[root].r) >> 1;
  if (pos <= mid) update(root << 1, pos, x);
  if (pos > mid) update(root << 1 | 1, pos, x);
  t[root].val = min(t[root << 1].val, t[root << 1 | 1].val);
}
int query(int root, int l, int r) {
  if (l <= t[root].l && t[root].r <= r) return t[root].val;
  int mid = (t[root].l + t[root].r) >> 1;
  int ans = 0x3f3f3f3f;
  if (l <= mid) ans = min(ans, query(root << 1, l, r));
  if (r > mid) ans = min(ans, query(root << 1 | 1, l, r));
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  build(1, 1, n);
  for (int i = 1; i <= n; ++i) {
    if (a[i] != 1) able[1] = 1;
    if (a[i] > 1 & query(1, 1, a[i] - 1) > last[a[i]]) able[a[i]] = 1;
    last[a[i]] = i;
    update(1, a[i], i);
  }
  for (int i = 2; i <= n + 1; ++i)
    if (query(1, 1, i - 1) > last[i]) able[i] = 1;
  int ans = 1;
  while (able[ans] && ans <= n + 1) ++ans;
  printf("%d\n", ans);
}
