#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 10;
int n, m, T;
int a[N], dat[N * 4], last[N];
set<int> s;
void pushup(int u) { dat[u] = min(dat[u << 1], dat[u << 1 | 1]); }
void modify(int u, int l, int r, int x, int y) {
  if (l == x && r == x) {
    dat[u] = y;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    modify(u << 1, l, mid, x, y);
  else
    modify(u << 1 | 1, mid + 1, r, x, y);
  pushup(u);
  return;
}
int query(int u, int l, int r, int L, int R) {
  if (L > R) return 0;
  if (L <= l && r <= R) return dat[u];
  int mid = (l + r) >> 1;
  int res = 1e9 + 10;
  if (L <= mid) res = min(res, query(u << 1, l, mid, L, R));
  if (mid < R) res = min(res, query(u << 1 | 1, mid + 1, r, L, R));
  return res;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] == 1)
      s.insert(2);
    else
      s.insert(1);
  }
  for (int i = 1; i <= n; ++i) {
    int x = a[i];
    if (query(1, 1, n, 1, x - 1) > last[x]) {
      s.insert(x);
    }
    modify(1, 1, n, x, i);
    last[x] = i;
  }
  for (int i = 1; i <= n + 1; ++i)
    if (last[i]) {
      if (query(1, 1, n, 1, i - 1) > last[i]) s.insert(i);
    } else {
      if (query(1, 1, n, 1, i - 1)) s.insert(i);
    }
  for (int i = 1;; ++i)
    if (!s.count(i)) {
      cout << i << endl;
      return 0;
    }
  return 0;
}
