#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5, mod = 998244353;
template <class o>
inline void qr(o &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  x *= f;
}
template <class o>
void qw(o x) {
  if (x / 10) qw(x / 10);
  putchar(x % 10 + 48);
}
template <class o>
void pr1(o x) {
  if (x < 0) putchar('-'), x = -x;
  qw(x);
  putchar(' ');
}
template <class o>
void pr2(o x) {
  if (x < 0) putchar('-'), x = -x;
  qw(x);
  puts("");
}
inline int ksm(int a, int b = mod - 2) {
  int ans = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) ans = 1ll * ans * a % mod;
  return ans;
}
inline int add(int a, int b) { return a += b, a >= mod ? a - mod : a; }
inline int sub(int a, int b) { return a -= b, a < 0 ? a + mod : a; }
int mn[N << 2];
void modify(int p, int l, int r, int pos, int d) {
  if (l == r) {
    mn[p] = d;
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid) modify(p << 1, l, mid, pos, d);
  if (pos > mid) modify(p << 1 | 1, mid + 1, r, pos, d);
  mn[p] = min(mn[p << 1], mn[p << 1 | 1]);
}
int query(int p, int l, int r, int L, int R) {
  if (L <= l && R >= r) return mn[p];
  int mid = l + r >> 1, val = 0x3f3f3f3f;
  if (L <= mid) val = query(p << 1, l, mid, L, R);
  if (R > mid) val = min(val, query(p << 1 | 1, mid + 1, r, L, R));
  return val;
}
int a[N], lst[N];
bool v[N];
void solve() {
  int n;
  qr(n);
  for (int i = 1; i <= n; ++i) {
    qr(a[i]);
    if (a[i] != 1) v[1] = 1;
    if (a[i] > 1 && query(1, 1, n, 1, a[i] - 1) > lst[a[i]]) v[a[i]] = 1;
    lst[a[i]] = i;
    modify(1, 1, n, a[i], i);
  }
  for (int i = 2; i <= n + 1; ++i)
    if (query(1, 1, n, 1, i - 1) > lst[i]) v[i] = 1;
  int ans = 1;
  for (; v[ans]; ++ans)
    ;
  pr2(ans);
}
int main() {
  solve();
  return 0;
}
