#include <bits/stdc++.h>
using namespace std;
vector<int> t;
void upd(int v, int x) {
  for (int i = v; i < t.size(); i |= (i + 1)) {
    t[i] += x;
  }
}
int get(int v) {
  int sum = 0;
  for (int i = v; i >= 0; i = (i & (i + 1)) - 1) {
    sum += t[i];
  }
  return sum;
}
int low_b(int s) {
  int k = 0;
  for (int i = 20; i > -1; i--) {
    if (k + (1 << i) - 1 >= t.size()) {
      continue;
    }
    if (t[k + (1 << i) - 1] < s) {
      s -= t[k + (1 << i) - 1];
      k += (1 << i);
    }
  }
  return k;
}
const int k = 600;
bool cmp(const vector<int>& a, const vector<int>& b) {
  if (a[0] / k == b[0] / k) return a[1] / k > b[1] / k;
  return a[0] / k < b[0] / k;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<vector<int>> pos(n);
  for (int i = 0; i < n; ++i) {
    pos[i].push_back(-1);
    pos[i].push_back(n);
  }
  for (int i = 0; i < n; ++i) {
    pos[a[i] - 1].push_back(i);
  }
  for (int i = 0; i < n; ++i) {
    sort(pos[i].begin(), pos[i].end());
  }
  vector<vector<int>> queries;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < pos[i].size() - 1; ++j) {
      int l = pos[i][j] + 1;
      int r = pos[i][j + 1] - 1;
      if (l <= r) queries.push_back({l, r, i + 1});
    }
  }
  queries.push_back({0, n - 1, n + 1});
  sort(queries.begin(), queries.end(), cmp);
  t.resize(n + 2);
  for (int i = 0; i < n + 2; ++i) {
    upd(i, 1);
  }
  vector<int> cnt(n + 1);
  int L = 0, R = -1;
  for (int i = 0; i < queries.size(); ++i) {
    int l = queries[i][0];
    int r = queries[i][1];
    while (L > l) {
      L--;
      cnt[a[L] - 1]++;
      if (cnt[a[L] - 1] == 1) {
        upd(a[L] - 1, -1);
      }
    }
    while (L < l) {
      cnt[a[L] - 1]--;
      if (cnt[a[L] - 1] == 0) {
        upd(a[L] - 1, 1);
      }
      L++;
    }
    while (R > r) {
      cnt[a[R] - 1]--;
      if (cnt[a[R] - 1] == 0) {
        upd(a[R] - 1, 1);
      }
      R--;
    }
    while (R < r) {
      R++;
      cnt[a[R] - 1]++;
      if (cnt[a[R] - 1] == 1) {
        upd(a[R] - 1, -1);
      }
    }
    queries[i].push_back(low_b(1) + 1);
  }
  vector<bool> ok(n + 2, false);
  for (auto elem : queries) {
    if (elem[2] == elem[3]) {
      ok[elem[2] - 1] = 1;
    }
  }
  int answe = 0;
  for (; answe <= n + 1; ++answe) {
    if (!ok[answe]) break;
  }
  cout << answe + 1;
}
