#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
template <typename T>
class SegTree {
 private:
  int len;
  vector<T> t;
  T merge(T a, T b) { return min(a, b); }
  void build(int u, int tl, int tr, const vector<T> &a) {
    if (tl == tr) {
      t[u] = a[tl];
    } else {
      int tm = (tl + tr) / 2;
      build(u * 2 + 1, tl, tm, a);
      build(u * 2 + 2, tm + 1, tr, a);
      t[u] = merge(t[u * 2 + 1], t[u * 2 + 2]);
    }
  }
  T minOn(int u, int tl, int tr, int l, int r) {
    if (r < tl || tr < l) return 1e9;
    if (l <= tl && tr <= r) return t[u];
    int tm = (tl + tr) / 2;
    return merge(minOn(u * 2 + 1, tl, tm, l, r),
                 minOn(u * 2 + 2, tm + 1, tr, l, r));
  }
  void setIn(int u, int tl, int tr, int i, T val) {
    if (tl == tr) {
      t[u] = val;
    } else {
      int tm = (tl + tr) / 2;
      if (i <= tm)
        setIn(u * 2 + 1, tl, tm, i, val);
      else
        setIn(u * 2 + 2, tm + 1, tr, i, val);
      t[u] = merge(t[u * 2 + 1], t[u * 2 + 2]);
    }
  }

 public:
  SegTree(const vector<T> &a) : len(a.size()) {
    t.resize(len * 4);
    build(0, 0, len - 1, a);
  }
  SegTree(int _len) : len(_len) { t.resize(len * 4); }
  T minOn(int l, int r) { return minOn(0, 0, len - 1, l, r); }
  void setIn(int i, T val) { setIn(0, 0, len - 1, i, val); }
};
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int cnt1 = 0;
  vector<bool> were(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    were[a[i]] = true;
    if (a[i] == 1) cnt1++;
  }
  if (cnt1 == n) {
    cout << "1\n";
    return 0;
  } else if (cnt1 == 0) {
    cout << "2\n";
    return 0;
  }
  vector<bool> f(n + 1);
  f[1] = true;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    cnt += were[i];
  }
  if (cnt == n) f[n] = true;
  SegTree<int> st(n + 1);
  for (int i = 1; i <= n; i++) {
    st.setIn(i, -1);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] > 1) {
      int last = st.minOn(a[i], a[i]);
      int minPos = st.minOn(1, a[i] - 1);
      if (minPos > last) f[a[i] - 1] = true;
    }
    st.setIn(a[i], i);
  }
  for (int i = 2; i <= n; i++) {
    int last = st.minOn(i, i);
    int minPos = st.minOn(1, i - 1);
    if (minPos > last) f[i - 1] = true;
  }
  int ans = -1;
  for (int i = 1; i <= n; i++) {
    if (!f[i]) {
      ans = i + 1;
      break;
    }
  }
  if (ans == -1) ans = n + 2;
  cout << ans << "\n";
  return 0;
}
