#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
struct Node {
  int x;
  int l, r;
} tr[N * 4];
int a[N], last[N];
void pushup(int u) { tr[u].x = min(tr[u << 1].x, tr[u << 1 | 1].x); }
void build(int u, int l, int r) {
  if (l == r) {
    tr[u] = {0, l, r};
  } else {
    int mid = l + r >> 1;
    build(u << 1, l, mid);
    build(u << 1 | 1, mid + 1, r);
    tr[u].l = l;
    tr[u].r = r;
  }
}
void update(int u, int t, int k) {
  if (tr[u].l == tr[u].r) {
    tr[u].x = k;
    return;
  }
  int mid = tr[u].l + tr[u].r >> 1;
  if (t <= mid) update(u << 1, t, k);
  if (t > mid) update(u << 1 | 1, t, k);
  pushup(u);
}
int query(int u, int l, int r) {
  if (tr[u].l >= l && tr[u].r <= r) {
    return tr[u].x;
  }
  int mid = tr[u].l + tr[u].r >> 1;
  int res = 0x3f3f3f3f;
  if (l <= mid) res = min(res, query(u << 1, l, r));
  if (r > mid) res = min(res, query(u << 1 | 1, l, r));
  return res;
}
bool f[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    int t = last[a[i]];
    if (a[i] > 1) {
      f[1] = true;
      int q = query(1, 1, a[i] - 1);
      if (q > t) {
        f[a[i]] = true;
      }
    }
    update(1, a[i], i);
    last[a[i]] = i;
  }
  for (int i = 2; i <= n + 1; i++) {
    int q = query(1, 1, i - 1);
    if (q > last[i]) {
      f[i] = true;
    }
  }
  for (int i = 1;; i++)
    if (!f[i]) {
      cout << i << endl;
      break;
    }
  return 0;
}
