#include <bits/stdc++.h>
using namespace std;
vector<int> cnt;
vector<int> count_zero;
int a, len;
void add(int x) {
  if (cnt[x - 1] == 0) {
    count_zero[(x - 1) / len]--;
  }
  cnt[x - 1]++;
}
void del(int x) {
  cnt[x - 1]--;
  if (cnt[x - 1] == 0) {
    count_zero[(x - 1) / len]++;
  }
}
int k = 100;
bool comp(pair<int, int> x, pair<int, int> y) {
  return make_pair(x.first / k, x.second) > make_pair(y.first / k, y.second);
}
int main() {
  int n;
  cin >> n;
  vector<vector<int>> Mo(n + 2);
  for (int i = 1; i < n + 2; i++) {
    Mo[i].push_back(-1);
  }
  vector<int> vec;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    vec.push_back(a);
    Mo[a].push_back(i);
  }
  for (int i = 1; i < n + 2; i++) {
    Mo[i].push_back(n);
  }
  int L = 0, R = -1;
  vector<int> res(0);
  vector<pair<int, int>> MO(0);
  for (int i = 1; i < n + 2; i++) {
    for (int j = 0; j < Mo[i].size() - 1; j++) {
      MO.push_back({Mo[i][j], Mo[i][j + 1]});
    }
  }
  sort(MO.begin(), MO.end(), comp);
  len = sqrt(n) + 1;
  a = n / len;
  if (n % len != 0) a++;
  count_zero.resize(a);
  cnt.resize(n);
  for (int i = 0; i < n; i++) {
    count_zero[i / len]++;
  }
  int size1 = MO.size();
  for (int i = 0; i < size1; i++) {
    int l = MO[i].first;
    int r = MO[i].second;
    if (r - l <= 1) continue;
    while (l + 1 < L) {
      L--;
      add(vec[L]);
    }
    while (r - 1 > R) {
      R++;
      add(vec[R]);
    }
    while (l >= L) {
      del(vec[L]);
      L++;
    }
    while (r <= R) {
      del(vec[R]);
      R--;
    }
    int flag = 0;
    for (int j = 0; j < a; j++) {
      if (count_zero[j] != 0) {
        for (int k = j * len; k < (j + 1) * len; k++) {
          if (cnt[k] == 0) {
            res.push_back(k + 1);
            flag = 1;
            break;
          }
        }
        break;
      }
    }
    if (flag == 0) {
      res.push_back(n + 1);
    }
  }
  int size = res.size();
  vector<int> h(n + 3, 0);
  for (int i = 0; i < size; i++) {
    h[res[i]] = 1;
  }
  for (int i = 1; i < n + 3; i++) {
    if (h[i] == 0) {
      cout << i;
      return 0;
    }
  }
  return 0;
}
