#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, ma, a[N], last[N];
int f[N << 2];
bool ok[N];
void update(int x, int xl, int xr, int pos, int val) {
  if (pos < xl || xr < pos || xl > xr) return;
  if (xl == xr) {
    f[x] = val;
    return;
  }
  int xm = (xl + xr) >> 1;
  update(x << 1, xl, xm, pos, val), update(x << 1 | 1, xm + 1, xr, pos, val);
  f[x] = min(f[x << 1], f[x << 1 | 1]);
}
int get(int x, int xl, int xr, int L, int R) {
  if (R < xl || xr < L || xl > xr) return n;
  if (L <= xl && xr <= R) return f[x];
  int xm = (xl + xr) >> 1;
  return min(get(x << 1, xl, xm, L, R), get(x << 1 | 1, xm + 1, xr, L, R));
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i], ma = max(ma, a[i]);
    if (a[i] != 1) ok[1] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] != 1 && get(1, 1, ma, 1, a[i] - 1) > last[a[i]]) ok[a[i]] = 1;
    last[a[i]] = i;
    update(1, 1, ma, a[i], i);
  }
  for (int i = 2; i <= ma + 1; i++)
    if (get(1, 1, ma, 1, i - 1) > last[i]) ok[i] = 1;
  for (int i = 1; i <= ma + 2; i++)
    if (!ok[i]) {
      cout << i;
      return 0;
    }
}
