#include <bits/stdc++.h>
using namespace std;
long long tr[1000000], a[1000000], last[1000000], vis[1000000];
long long build(long long p, long long l, long long r) {
  if (l > r) return 0;
  if (l == r) return tr[p] = last[l];
  return tr[p] = max(build(p * 2, l, (l + r) / 2),
                     build(p * 2 + 1, (l + r) / 2 + 1, r));
}
long long add(long long p, long long pl, long long pr, long long x,
              long long v) {
  if (pl == x && pr == x) return tr[p] = v;
  if (pl <= x && pr >= x) {
    tr[p] = max(add(p * 2, pl, (pl + pr) / 2, x, v),
                add(p * 2 + 1, (pl + pr) / 2 + 1, pr, x, v));
    return tr[p];
  }
  return tr[p];
}
long long qu(long long p, long long pl, long long pr, long long l,
             long long r) {
  if (pr < l || pl > r) return 0;
  if (pl >= l && pr <= r) {
    return tr[p];
  } else {
    return max(qu(p * 2, pl, (pl + pr) / 2, l, r),
               qu(p * 2 + 1, (pl + pr) / 2 + 1, pr, l, r));
  }
}
int main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    last[i] = n + 1;
  }
  last[n + 1] = n + 1;
  build(1, 1, n + 1);
  for (int i = n; i >= 1; i--) {
    if (a[i] == 1) {
      if (qu(1, 1, n + 1, 1, 1) > i + 1) vis[a[i]] = 1;
    } else if (qu(1, 1, n + 1, 1, a[i] - 1) < qu(1, 1, n + 1, a[i], a[i])) {
      vis[a[i]] = 1;
    }
    add(1, 1, n + 1, a[i], i);
  }
  for (int i = 1; i <= n + 1; i++) {
    if (i == 1) {
      if (qu(1, 1, n + 1, 1, 1) > 1) vis[1] = 1;
    } else if (qu(1, 1, n + 1, 1, i - 1) < qu(1, 1, n + 1, i, i)) {
      vis[i] = 1;
    }
  }
  for (int i = 1; i <= n + 1; i++)
    if (!vis[i]) {
      cout << i;
      return 0;
    }
  cout << n + 2;
  return 0;
}
