#include <bits/stdc++.h>
using namespace std;
const int maxn = 112345;
int n, a[maxn], last[maxn], nex[maxn];
bool vis[maxn];
int main() {
  scanf("%d", &n);
  for (int(i) = (1); (i) <= (n); (i)++) scanf("%d", a + i);
  for (int(i) = (1); (i) <= (n); (i)++)
    if (a[i] > 1) vis[1] = true;
  if (!vis[1]) {
    puts("1");
    return 0;
  }
  fill(last + 1, last + n + 2, n + 1);
  for (int(i) = (n); (i) >= (1); (i)--) {
    nex[i] = last[a[i]];
    last[a[i]] = i;
  }
  int mx = 0;
  multiset<pair<int, int> > peaks;
  for (int(i) = (1); (i) <= (n + 1); (i)++)
    if (last[i] > mx) {
      vis[i] = true;
      peaks.emplace(i, last[i]);
      mx = max(mx, last[i]);
    }
  for (int(i) = (2); (i) <= (n); (i)++) {
    auto it = peaks.lower_bound(make_pair(a[i - 1], 0));
    if (it == peaks.begin() || prev(it)->second < nex[i - 1]) {
      vis[a[i - 1]] = true;
      while (it != peaks.end() && it->second <= nex[i - 1]) {
        it++;
        peaks.erase(prev(it));
      }
      peaks.emplace(a[i - 1], nex[i - 1]);
    }
  }
  for (int(i) = (1); (i) <= (n + 2); (i)++)
    if (!vis[i]) {
      printf("%d", i);
      return 0;
    }
}
