#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
class SegmentTreeMin {
 public:
  int n;
  vector<long long> vect;
  SegmentTreeMin(int _n) : n(_n) {
    vect.resize(2 * n);
    fill(vect.begin(), vect.end(), 1e10);
  }
  void modify(int p, long long value) {
    for (vect[p += n] = value; p > 1; p >>= 1) {
      vect[p >> 1] = min(vect[p], vect[p ^ 1]);
    }
  }
  long long query(int l, int r) {
    long long res = 1e10;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) res = min(res, vect[l++]);
      if (r & 1) res = min(res, vect[--r]);
    }
    return res;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<vector<int>> vp(n + 2), vq(n + 1);
  for (int i = 1; i <= n; i++) {
    vp[a[i]].push_back(i);
  }
  vector<bool> hasm(n + 3);
  for (int i = 1; i <= n + 1; i++) {
    if (!vp[i].size()) {
      hasm[i] = 1;
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!vp[i].size()) continue;
    if (vp[i][0] > 1) {
      vq[vp[i][0] - 1].push_back(1);
    }
    for (int j = 1; j < vp[i].size(); j++) {
      if (vp[i][j - 1] < vp[i][j] - 1) {
        vq[vp[i][j] - 1].push_back(vp[i][j - 1] + 1);
      }
    }
    if (vp[i].back() < n) {
      vq[n].push_back(vp[i].back() + 1);
    }
  }
  vector<bool> al(n + 10, 1);
  vector<int> lp(n + 2);
  long long bp = 1;
  SegmentTreeMin st(n + 1);
  for (int i = 1; i <= n; i++) {
    int x = a[i];
    al[x] = 0;
    st.modify(i, x);
    st.modify(lp[x], n + 10);
    lp[x] = i;
    for (int y : vq[i]) {
      while (!al[bp]) bp++;
      long long z = min(bp, st.query(0, y));
      hasm[z] = 1;
    }
  }
  for (int i = 1; i <= n + 2; i++) {
    if (!hasm[i]) {
      cout << i;
      return 0;
    }
  }
  return 0;
}
