#include <bits/stdc++.h>
using namespace std;
const int INF = -1;
class segtree {
 public:
  struct node {
    int val = 1e9;
    void apply(int l, int r) { val = INF; }
    void apply(int l, int r, int v) { val = v; }
  };
  node unite(const node &a, const node &b) const {
    node res;
    res.val = min(a.val, b.val);
    return res;
  }
  inline void push(int x, int l, int r) { return; }
  inline void pull(int x) { tree[x] = unite(tree[2 * x], tree[2 * x + 1]); }
  int n;
  vector<node> tree;
  segtree(int _n) : n(_n) {
    assert(n > 0);
    tree.resize(4 * n);
    build(1, 0, n - 1);
  }
  template <typename M>
  segtree(const vector<M> &v) {
    n = v.size();
    assert(n > 0);
    tree.resize(4 * n);
    build(1, 0, n - 1, v);
  }
  node get(int ll, int rr) {
    assert(0 <= ll && ll <= rr && rr <= n - 1);
    return get(1, 0, n - 1, ll, rr);
  }
  template <typename... M>
  void modify(int ll, int rr, const M &...v) {
    assert(0 <= ll && ll <= rr && rr <= n - 1);
    modify(1, 0, n - 1, ll, rr, v...);
  }

 private:
  void build(int x, int l, int r) {
    if (l == r) {
      tree[x].apply(l, r);
      return;
    }
    int mid = (l + r) >> 1;
    build(2 * x, l, mid);
    build(2 * x + 1, mid + 1, r);
    pull(x);
  }
  template <typename M>
  void build(int x, int l, int r, const vector<M> &v) {
    if (l == r) {
      tree[x].apply(l, r, v[l]);
      return;
    }
    int mid = (l + r) >> 1;
    build(2 * x, l, mid, v);
    build(2 * x + 1, mid + 1, r, v);
    pull(x);
  }
  node get(int x, int l, int r, int ll, int rr) {
    node res{};
    if (ll > r || l > rr) return res;
    if (ll <= l && r <= rr) return tree[x];
    int mid = (l + r) >> 1;
    push(x, l, r);
    res = unite(get(2 * x, l, mid, ll, rr), get(2 * x + 1, mid + 1, r, ll, rr));
    pull(x);
    return res;
  }
  template <typename... M>
  void modify(int x, int l, int r, int ll, int rr, const M &...v) {
    if (ll > r || l > rr) return;
    if (ll <= l && r <= rr) {
      tree[x].apply(l, r, v...);
      return;
    }
    int mid = (l + r) >> 1;
    push(x, l, r);
    modify(2 * x, l, mid, ll, rr, v...);
    modify(2 * x + 1, mid + 1, r, ll, rr, v...);
    pull(x);
  }
};
void run_case() {
  int n;
  cin >> n;
  vector<int> a(n);
  segtree st(n + 2);
  vector<bool> res(n + 2, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
    if (a[i] != 0) res[0] = 1;
  }
  for (int i = 0; i < n; i++) {
    int v = st.get(a[i], a[i]).val;
    if (a[i] != 0) {
      int small = st.get(0, a[i] - 1).val;
      if (small > v) res[a[i]] = 1;
    }
    st.modify(a[i], a[i], i);
  }
  for (int i = 0; i < n + 1; i++) {
    int v = st.get(i + 1, i + 1).val;
    int small = st.get(0, i).val;
    if (small > v) res[i + 1] = 1;
  }
  for (int i = 0; i < n + 2; i++) {
    if (!res[i]) {
      cout << i + 1 << '\n';
      return;
    }
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  if (fopen("input.in", "r"))
    freopen("input.in", "r", stdin), freopen("output.out", "w", stdout);
  int t;
  t = 1;
  while (t--) {
    run_case();
  }
}
