#include <bits/stdc++.h>
using namespace std;
struct segtree {
  pair<long long, long long> base = {LLONG_MAX, LLONG_MAX};
  pair<long long, long long> comb(pair<long long, long long> a,
                                  pair<long long, long long> b) {
    return min(a, b);
  }
  int n;
  vector<pair<long long, long long> > v;
  segtree(int x) : n(x) {
    v.resize(2 * n + 5, base);
    for (int q = n; q < 2 * n + 5; q++) v[q].second = q - n;
  }
  void update(int i, long long x) {
    i += n;
    v[i].first = x;
    for (i /= 2; i >= 1; i /= 2) {
      v[i] = comb(v[2 * i], v[2 * i + 1]);
    }
  }
  pair<long long, long long> get(int l, int r) {
    pair<long long, long long> ans = base;
    for (l += n, r += n; l <= r; l /= 2, r /= 2) {
      if (l % 2) ans = comb(ans, v[l++]);
      if ((r + 1) % 2) ans = comb(ans, v[r--]);
    }
    return ans;
  }
  void build(vector<pair<long long, long long> > &x) {
    for (int q = 0; q < (int)x.size(); q++) {
      v[q + n] = x[q];
    }
    for (int q = n - 1; q >= 1; q--) {
      v[q] = comb(v[2 * q], v[2 * q + 1]);
    }
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int q = 1; q <= n; q++) cin >> a[q];
  segtree st(200005);
  vector<bool> exists(200005);
  for (int q = 1; q <= n + 10; q++) st.update(q, -n - 1 + q);
  for (int q = 1; q <= n; q++) {
    pair<long long, long long> x = st.get(1, a[q]);
    if (x.second == a[q] && a[q] != 1) exists[a[q]] = true;
    st.update(a[q], q);
  }
  for (int q = 1; q <= n + 1; q++) {
    pair<long long, long long> x = st.get(1, q);
    if (x.second == q && q != 1) exists[q] = true;
  }
  for (int q = 1; q <= n; q++)
    if (a[q] != 1) exists[1] = true;
  for (int q = 1; q < 200005; q++) {
    if (!exists[q]) {
      cout << q << '\n';
      return 0;
    }
  }
  return 0;
}
