#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f;
int n, m, Q, K, T;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int a[maxn], las[maxn];
bool can[maxn];
int Min[maxn << 2];
void pushup(int rt) { Min[rt] = min(Min[rt << 1], Min[rt << 1 | 1]); }
void update(int rt, int l, int r, int pos, int k) {
  if (l == r) return (void)(Min[rt] = k);
  if (pos <= ((l + r) / 2))
    update(rt << 1, l, ((l + r) / 2), pos, k);
  else
    update(rt << 1 | 1, ((l + r) / 2) + 1, r, pos, k);
  pushup(rt);
  return;
}
int query(int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) return Min[rt];
  int res = inf;
  if (L <= ((l + r) / 2))
    res = min(res, query(rt << 1, l, ((l + r) / 2), L, R));
  if (R > ((l + r) / 2))
    res = min(res, query(rt << 1 | 1, ((l + r) / 2) + 1, r, L, R));
  return res;
}
signed main() {
  n = read();
  for (int i = (1); i <= (n); ++i) a[i] = read();
  for (int i = (1); i <= (n + 2); ++i) can[i] = 0;
  for (int i = (1); i <= (n); ++i) {
    if (a[i] != 1) can[1] = 1;
    if (a[i] > 1 && query(1, 1, n, 1, a[i] - 1) > las[a[i]]) can[a[i]] = 1;
    las[a[i]] = i;
    update(1, 1, n, a[i], i);
  }
  for (int i = (2); i <= (n + 1); ++i)
    if (query(1, 1, n, 1, i - 1) > las[i]) can[i] = 1;
  for (int i = (1); i <= (n + 2); ++i) {
    if (!can[i]) printf("%d\n", i), exit(0);
  }
  return 0;
}
