#include <bits/stdc++.h>
using namespace std;
mt19937 mt_rand(
    chrono::high_resolution_clock::now().time_since_epoch().count());
const int INF = 2e9;
const long long ML = 4e18;
int t[4 * 100005];
void modify(int k, int l, int r, int pos, int val) {
  if (l == r) {
    t[k] = val;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    modify(k << 1, l, mid, pos, val);
  else
    modify(k + k + 1, mid + 1, r, pos, val);
  t[k] = min(t[k + k + 1], t[k << 1]);
}
int query(int k, int l, int r, int x) {
  if (l == r) return t[k];
  int mid = (l + r) >> 1;
  if (x <= mid) return query(k << 1, l, mid, x);
  return min(t[k << 1], query(k + k + 1, mid + 1, r, x));
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = (1); i < (n + 1); ++i) cin >> a[i];
  vector<bool> vis(n + 3, false);
  vector<int> last(n + 1, 0);
  for (int i = (1); i < (n + 1); ++i) {
    int x = a[i];
    if (x > 1) vis[1] = 1;
    if (last[x] + 1 < i) {
      int p = query(1, 1, n, x - 1);
      if (p > last[x]) vis[x] = 1;
    }
    modify(1, 1, n, a[i], i);
    last[x] = i;
  }
  for (int i = (2); i < (n + 1); ++i) {
    int p = query(1, 1, n, i - 1);
    if (p > last[i]) vis[i] = 1;
  }
  int p = *max_element((a).begin(), (a).end());
  if (query(1, 1, n, p) > 0) vis[p + 1] = 1;
  for (int i = (1); i < (n + 3); ++i)
    if (!vis[i]) {
      cout << i << endl;
      break;
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
