#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, INF = 0x3f3f3f3f;
int n, ans = 1;
int a[N], b[N], ls[N];
int s[N << 2];
void mdf(int p, int l, int r, int x, int d) {
  if (l == r) {
    s[p] = d;
    return;
  }
  int mid = l + r >> 1;
  if (x <= mid)
    mdf(p << 1, l, mid, x, d);
  else
    mdf(p << 1 | 1, mid + 1, r, x, d);
  s[p] = min(s[p << 1], s[p << 1 | 1]);
}
int qry(int p, int l, int r, int L, int R) {
  if (l > R || r < L) return INF;
  if (L <= l && r <= R) return s[p];
  int mid = l + r >> 1;
  return min(qry(p << 1, l, mid, L, R), qry(p << 1 | 1, mid + 1, r, L, R));
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    if (a[i] > 1) {
      b[1] = 1;
      if (qry(1, 1, n, 1, a[i] - 1) > ls[a[i]]) b[a[i]] = 1;
    }
    ls[a[i]] = i;
    mdf(1, 1, n, a[i], i);
  }
  for (int i = 2; i <= n + 1; i++)
    if (qry(1, 1, n, 1, i - 1) > ls[i]) b[i] = 1;
  for (; ans <= n + 1 && b[ans]; ans++)
    ;
  printf("%d\n", ans);
}
