#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long long int INF = 1e9;
struct SegTree {
  long long int n;
  vector<long long int> tree;
  SegTree(long long int n) {
    this->n = n;
    tree.resize(4 * n + 5, 0);
  }
  long long int query(long long int node, long long int start,
                      long long int end, long long int l, long long int r) {
    if (start > r || end < l) {
      return INF;
    } else if (start >= l && end <= r) {
      return tree[node];
    } else {
      long long int mid = (start + end) / 2;
      long long int p1 = query(2 * node, start, mid, l, r);
      long long int p2 = query(2 * node + 1, mid + 1, end, l, r);
      return min(p1, p2);
    }
  }
  void update(long long int node, long long int start, long long int end,
              long long int idx, long long int val) {
    if (start == end) {
      tree[node] = val;
    } else {
      long long int mid = (start + end) / 2;
      if (idx <= mid) {
        update(2 * node, start, mid, idx, val);
      } else {
        update(2 * node + 1, mid + 1, end, idx, val);
      }
      tree[node] = min(tree[2 * node], tree[2 * node + 1]);
    }
  }
  void update(long long int idx, long long int val) {
    update(1, 1, n, idx, val);
  }
  long long int query(long long int l, long long int r) {
    return query(1, 1, n, l, r);
  }
};
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> a(n + 5), last(n + 5, 0);
  SegTree tree(n + 5);
  vector<bool> ok(n + 5, false);
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != 1) ok[1] = true;
  }
  for (long long int i = 1; i <= n; i++) {
    if (a[i] != 1) {
      long long int l = tree.query(1, a[i] - 1);
      if (l > last[a[i]]) ok[a[i]] = true;
    }
    last[a[i]] = i;
    tree.update(a[i], i);
  }
  for (long long int i = 2; i <= n + 1; i++) {
    long long int l = tree.query(1, i - 1);
    if (l > last[i]) ok[i] = true;
  }
  for (long long int i = 1; i <= n + 2; i++) {
    if (!ok[i]) {
      cout << i << "\n";
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
