#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5;
int a[MAX + 5], last[MAX + 5], vis[MAX + 5];
int val[MAX << 2];
int query(int k, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return val[k];
  int mid = (l + r) >> 1;
  if (qr <= mid)
    return query(k << 1, l, mid, ql, qr);
  else if (ql > mid)
    return query(k << 1 | 1, mid + 1, r, ql, qr);
  else
    return min(query(k << 1, l, mid, ql, qr),
               query(k << 1 | 1, mid + 1, r, ql, qr));
}
void update(int k, int l, int r, int pos, int v) {
  if (l == r) {
    val[k] = v;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(k << 1, l, mid, pos, v);
  else
    update(k << 1 | 1, mid + 1, r, pos, v);
  val[k] = min(val[k << 1], val[k << 1 | 1]);
}
int main() {
  int n;
  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) vis[1] = 1;
    if (a[i] > 1 && query(1, 1, n, 1, a[i] - 1) > last[a[i]]) vis[a[i]] = 1;
    last[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) > last[i]) vis[i] = 1;
  int ans = 1;
  while (vis[ans]) ans++;
  printf("%d\n", ans);
  return 0;
}
