#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int a[maxn], tree[maxn << 1];
int pre[maxn];
bool vis[maxn];
void update(int k, int l, int r, int p, int v) {
  if (l == r) {
    tree[k] = v;
    return;
  }
  int mid = l + r >> 1;
  if (mid >= p) update(k << 1, l, mid, p, v);
  if (mid < p) update(k << 1 | 1, mid + 1, r, p, v);
  tree[k] = min(tree[k << 1], tree[k << 1 | 1]);
}
int query(int k, int l, int r, int L, int R) {
  if (L <= l && r <= R) return tree[k];
  int mid = l + r >> 1;
  int ans = 0x3f3f3f3f;
  if (mid >= L) ans = min(ans, query(k << 1, l, mid, L, R));
  if (mid < R) ans = min(ans, query(k << 1 | 1, mid + 1, r, L, R));
  return ans;
}
int main() {
  int n;
  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) {
      pre[a[i]] = i;
      update(1, 1, n, a[i], i);
      continue;
    }
    if (a[i] != 1) vis[1] = true;
    int p = query(1, 1, n, 1, a[i] - 1);
    if (a[i] != 1 && p > pre[a[i]]) vis[a[i]] = true;
    pre[a[i]] = i;
    update(1, 1, n, a[i], i);
  }
  for (int i = 2; i <= n + 1; i++) {
    int p = query(1, 1, n, 1, i - 1);
    if (p > pre[i]) vis[i] = true;
  }
  int ans = 1;
  while (vis[ans]) ans++;
  printf("%d\n", ans);
  return 0;
}
