#include <bits/stdc++.h>
using namespace std;
vector<int> tree;
vector<int> mod;
int inf = 1000000000;
int get(int v, int l, int r, int u, int w) {
  if (l >= w || r <= u) {
    return -1;
  }
  if (u <= l && r <= w) {
    return tree[v];
  }
  int m = (r + l) / 2;
  int a = get(v * 2 + 1, l, m, u, w);
  int b = get(v * 2 + 2, m, r, u, w);
  return max(a, b);
}
void update(int v, int l, int r, int u, int w, int delt) {
  if (l >= w || r <= u) {
    return;
  }
  if (u <= l && r <= w) {
    mod[v] += delt;
    tree[v] += delt;
    return;
  }
  int m = (r + l) / 2;
  update(v * 2 + 1, l, m, u, w, delt);
  update(v * 2 + 2, m, r, u, w, delt);
  tree[v] = max(tree[v * 2 + 1], tree[v * 2 + 2]) + mod[v];
}
signed main() {
  int n;
  cin >> n;
  tree.resize(4 * n + 100);
  mod.resize(4 * n + 100);
  vector<int> a(n);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
    cnt = max(cnt, a[i]);
  }
  if (cnt == 0) {
    cout << 1;
    return 0;
  }
  vector<int> leftelement(n + 2, n);
  vector<int> nextelement(n);
  for (int i = n - 1; i > -1; i--) {
    int c = a[i];
    nextelement[i] = leftelement[c];
    leftelement[c] = i;
  }
  vector<pair<int, pair<int, int>>> def;
  map<pair<int, pair<int, int>>, bool> ans;
  for (int i = 0; i < n; i++) {
    def.push_back({-1, {leftelement[i], i}});
    def.push_back({i, {nextelement[i], a[i]}});
  }
  def.push_back({-1, {n, n}});
  def.push_back({-1, {n, n + 1}});
  int m = def.size();
  sort(def.begin(), def.end());
  int l = -1;
  for (int i = 0; i < n + 2; i++) {
    update(0, 0, n + 2, i, i + 1, leftelement[i]);
  }
  for (int i = 0; i < m; i++) {
    int u = def[i].first, w = def[i].second.first, x = def[i].second.second;
    while (l < u) {
      l++;
      update(0, 0, n + 2, x, x + 1, nextelement[l] - l);
    }
    int y = get(0, 0, n + 2, 0, x);
    if (y < w) {
      ans[def[i]] = true;
      if (x == 3) {
      }
    } else {
      ans[def[i]] = false;
    }
  }
  vector<vector<int>> sps(n + 2, {-1});
  for (int i = 0; i < n; i++) {
    sps[a[i]].push_back(i);
  }
  for (int i = 0; i < n + 2; i++) {
    sps[i].push_back(n);
  }
  for (int i = 0; i < n + 2; i++) {
    bool t = false;
    int k = sps[i].size();
    for (int j = 0; j < k - 1; j++) {
      if (ans[{sps[i][j], {sps[i][j + 1], i}}] == true) {
        t = true;
      }
    }
    if (t == false) {
      cout << i + 1;
      return 0;
    }
  }
  return 0;
}
