#include <bits/stdc++.h>
using namespace std;
class segmentTree {
 public:
  int* tree;
  int N;
  int size;
  void update(int qidx, int val) { update(qidx, val, 0, N - 1, 0); }
  void update(int qidx, int val, int left, int right, int idx) {
    if (left == right && left == qidx) {
      tree[idx] = val;
    } else if (qidx >= left && qidx <= right) {
      int mid = (left + right) / 2;
      update(qidx, val, left, mid, 2 * idx + 1);
      update(qidx, val, mid + 1, right, 2 * idx + 2);
      tree[idx] = min(tree[2 * idx + 1], tree[2 * idx + 2]);
    }
  }
  int query(int qleft, int qright) { return query(qleft, qright, 0, N - 1, 0); }
  int query(int qleft, int qright, int left, int right, int index) {
    if (left >= qleft && right <= qright) return tree[index];
    if (right < qleft || left > qright) return INT_MAX;
    int mid = (left + right) / 2;
    return min(query(qleft, qright, left, mid, 2 * index + 1),
               query(qleft, qright, mid + 1, right, 2 * index + 2));
  }
  segmentTree(int n) {
    N = n;
    int start = 2;
    while ((start - 1) < 2 * N) start *= 2;
    size = start - 1;
    tree = new int[size];
    memset(tree, -1, sizeof(int) * size);
  }
};
const int MX = 1e5 + 69;
int used[MX], used2[MX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(used, 0, sizeof used);
  memset(used2, 0, sizeof used2);
  int n;
  cin >> n;
  segmentTree tree = segmentTree(n + 1);
  int totmex = 1;
  vector<int> submex;
  for (int i = 0; i < n; i++) {
    int w;
    cin >> w;
    used[w]++;
    while (used[totmex]) totmex++;
    if (w != 1) {
      submex.push_back(1);
    } else {
      tree.update(1, i);
      continue;
    }
    int lastw = tree.query(w, w);
    int minbelow = tree.query(1, w - 1);
    if (minbelow > lastw) submex.push_back(w);
    tree.update(w, i);
  }
  for (int w = 2; w <= n; w++) {
    int lastw = tree.query(w, w);
    int minbelow = tree.query(1, w - 1);
    if (minbelow > lastw) submex.push_back(w);
  }
  submex.push_back(totmex);
  for (int v : submex) used2[v]++;
  for (int ans = 1; ans < 1e9; ans++)
    if (!used2[ans]) {
      cout << ans << '\n';
      exit(0);
    }
}
