#include <bits/stdc++.h>
using namespace std;
int tree[4 * 100009];
void update(int ind, int st, int ed, int i, int v) {
  if (st > i || ed < i) return;
  if (st == ed) {
    tree[ind] = v;
    return;
  }
  if (i <= ((st + ed) >> 1))
    update((ind + ind), st, ((st + ed) >> 1), i, v);
  else
    update((ind + ind + 1), ((st + ed) >> 1) + 1, ed, i, v);
  tree[ind] = min(tree[(ind + ind)], tree[(ind + ind + 1)]);
}
int query(int ind, int st, int ed, int i, int j) {
  if (i > j) return 0;
  if (st > j || ed < i) {
    return INT_MAX;
  } else if (st >= i && ed <= j) {
    return tree[ind];
  } else
    return min(query((ind + ind), st, ((st + ed) >> 1), i, j),
               query((ind + ind + 1), ((st + ed) >> 1) + 1, ed, i, j));
}
int ar[100009], last[100009];
bool mex[100009];
int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
    if (ar[i] > 1) mex[1] = true;
  }
  for (i = 1; i <= n; i++) {
    int l = last[ar[i]];
    int ql = query(1, 1, n, 1, ar[i] - 1);
    if (ql > l) {
      mex[ar[i]] = true;
    }
    last[ar[i]] = i;
    update(1, 1, n, ar[i], i);
  }
  for (i = 2; i <= n + 1; i++) {
    int l = last[i];
    if (l == n) continue;
    int ql = query(1, 1, n, 1, i - 1);
    if (ql > l) {
      mex[i] = true;
    }
  }
  int res = 1;
  for (i = 1; i <= n + 2; i++) {
    if (!mex[i]) {
      res = i;
      break;
    }
  }
  printf("%d\n", res);
  return 0;
}
