#include <bits/stdc++.h>
using namespace std;
class intervalac {
  vector<int> l, r, v;

 public:
  void init(int n) {
    int n2 = 1;
    while (n2 < n) n2 <<= 1;
    l.resize(n2 * 2);
    r.resize(n2 * 2);
    v.resize(n2 * 2, -1);
    for (int i = n2 - 1; i < n2 * 2; i++) l[i] = r[i] = i - (n2 - 1);
    for (int i = n2 - 2; i >= 0; i--) {
      l[i] = l[i * 2 + 1];
      r[i] = r[i * 2 + 2];
    }
  }
  void update(int i, int d, int vr = 0) {
    if (l[vr] > i || r[vr] < i) return;
    if (l[vr] == i && r[vr] == i) {
      v[vr] = d;
      return;
    }
    update(i, d, vr * 2 + 1);
    update(i, d, vr * 2 + 2);
    v[vr] = min(v[vr * 2 + 1], v[vr * 2 + 2]);
  }
  int mini(int li, int ri, int vr = 0) {
    if (l[vr] > ri || li > r[vr]) return 1e9;
    if (l[vr] >= li && r[vr] <= ri) return v[vr];
    return min(mini(li, ri, vr * 2 + 1), mini(li, ri, vr * 2 + 2));
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (*max_element(a.begin(), a.end()) == 1) {
    cout << 1 << "\n";
    return 0;
  }
  intervalac in;
  in.init(n + 2);
  vector<int> f(n + 2, 0);
  for (int i = 0; i < n; i++) {
    if (in.mini(1, a[i] - 1) > in.mini(a[i], a[i])) {
      f[a[i]] = 1;
    }
    in.update(a[i], i);
  }
  for (int i = 1; i <= n + 1; i++) {
    if (in.mini(1, i - 1) > in.mini(i, i)) {
      f[i] = 1;
    }
  }
  for (int i = 1; i <= n + 1; i++) {
    if (!f[i]) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << n + 2 << "\n";
  return 0;
}
