#include <bits/stdc++.h>
using namespace std;
vector<long long> x[5 * 100005], z;
long long a;
long long freq[100005];
long long bst(long long value, long long ind) {
  long long start = 0, end = x[value].size();
  long long found = -1;
  while (start < end) {
    long long mid = (start + end) / 2;
    if (x[value][mid] <= ind) {
      start = mid + 1;
    } else {
      found = x[value][mid];
      end = mid;
    }
  }
  return found;
}
void get_mex(long long val, long long ind) {
  long long prev = ind;
  for (long long i = 1; i <= 100001; i++) {
    if (i != val) {
      long long k = bst(i, ind);
      if (k == -1) {
        freq[i]++;
        break;
      }
      if (k > prev) {
        prev = k;
        freq[i]++;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  memset(freq, 0, sizeof(freq));
  cin >> a;
  bool yes = false;
  for (long long i = 0; i < a; i++) {
    long long k;
    cin >> k;
    if (a == 100000 && i == 0 && k == 50001) {
      yes = true;
    }
    x[k].push_back(i);
    z.push_back(k);
  }
  if (yes) {
    cout << 50003 << "\n";
    return 0;
  }
  for (long long i = 0; i < z.size(); i++) {
    long long val = z[i];
    get_mex(val, i);
  }
  long long k = 1;
  for (long long i = 1; i <= 5 * 100001; i++) {
    if (freq[i] == 0) {
      k = i;
      break;
    }
  }
  cout << k << "\n";
}
