#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5 + 4;
struct Node {
  int l, r, val;
  Node* lc;
  Node* rc;
  Node(int l_, int r_) : l(l_), r(r_), val(-1) {
    lc = rc = nullptr;
    if (l == r) {
      return;
    }
    int m = (l + r) / 2;
    lc = new Node(l, m);
    rc = new Node(m + 1, r);
  }
  void update(int x, int pos) {
    if (l == r) {
      val = x;
      return;
    }
    int m = (l + r) / 2;
    if (pos <= m) {
      lc->update(x, pos);
    } else {
      rc->update(x, pos);
    }
    val = min(rc->val, lc->val);
  }
  int compute(int l_, int r_) {
    if (l_ == l && r_ == r) {
      return val;
    }
    int m = (l + r) / 2;
    if (r_ <= m) {
      return lc->compute(l_, r_);
    } else if (l_ > m) {
      return rc->compute(l_, r_);
    } else {
      return min(lc->compute(l_, m), rc->compute(m + 1, r_));
    }
  }
};
bool used[N];
int l[N], n;
vector<int> a;
void read() {
  cin >> n;
  a.resize(n);
  for (int& i : a) cin >> i;
}
void solve() {
  read();
  Node* root = new Node(1, n + 4);
  for (int i = 0; i < n; ++i) {
    int u = a[i];
    int cur;
    if (u == 1) {
      cur = (l[u] == i - 1 ? -1 : i - 1);
    } else {
      cur = root->compute(1, u - 1);
    }
    used[u] |= (cur >= l[u]);
    l[u] = i;
    root->update(i, u);
  }
  used[1] |= (l[1] < n - 1);
  for (int i = 2; i <= n + 1; ++i) {
    int cur = root->compute(1, i - 1);
    used[i] |= (cur >= l[i]);
  }
  for (int i = 1; i <= n + 2; ++i) {
    if (!used[i]) {
      cout << i << "\n";
      return;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cout.tie(0), cin.tie(0);
  int z = 1;
  while (z--) {
    solve();
  }
  return 0;
}
