#include <bits/stdc++.h>
using namespace std;
int power[31] = {0};
bool ok[100003] = {0};
int last[100001] = {0};
int N;
const int inf = 1e9;
vector<pair<int, pair<int, int>>> segtree;
void fill(int v) {
  if (2 * v + 1 < power[N + 1] - 1) {
    fill(2 * v + 1);
    fill(2 * v + 2);
    segtree[v].first = min(segtree[2 * v + 1].first, segtree[2 * v + 2].first);
    segtree[v].second.first = segtree[2 * v + 1].second.first;
    segtree[v].second.second = segtree[2 * v + 2].second.second;
  } else {
    return;
  }
}
void update(int i, int del) {
  int curr = i;
  segtree[curr].first += del;
  while (curr > 0) {
    curr = (curr - 1) / 2;
    segtree[curr].first =
        min(segtree[2 * curr + 1].first, segtree[2 * curr + 2].first);
  }
}
int mn(int l, int r, int v) {
  if (segtree[v].second.first >= l && segtree[v].second.second <= r) {
    return segtree[v].first;
  } else if (segtree[v].second.second < l || segtree[v].second.first > r) {
    return inf;
  } else {
    return min(mn(l, r, 2 * v + 1), mn(l, r, 2 * v + 2));
  }
}
void solve() {
  int n;
  cin >> n;
  for (int j = 0; j <= 30; j++) {
    if (power[j] >= n) {
      N = j;
      break;
    }
  }
  segtree.resize(power[N + 1] - 1);
  for (int j = power[N] - 1; j < power[N + 1] - 1; j++) {
    segtree[j].first = -1;
    segtree[j].second.first = j - power[N] + 1;
    segtree[j].second.second = j - power[N] + 1;
  }
  fill(0);
  for (int j = 1; j <= n; j++) last[j] = -1;
  vector<int> v(n);
  for (int j = 0; j < n; j++) {
    cin >> v[j];
  }
  bool nonone = 0;
  bool one = 0;
  for (int j = 0; j < n; j++) {
    if (v[j] != 1) {
      nonone = 1;
    } else
      one = 1;
  }
  if (!nonone) {
    cout << 1 << "\n";
    return;
  }
  if (!one) {
    cout << 2 << "\n";
    return;
  }
  for (int i = 0; i < n; i++) {
    if (v[i] == 1) {
      update(1 + power[N] - 1, i - last[1]);
      last[1] = i;
      continue;
    }
    int l = mn(v[i], v[i], 0) + 1;
    int r = i - 1;
    if (l <= r) {
      if (mn(1, v[i] - 1, 0) >= l) {
        ok[v[i]] = 1;
      }
    }
    update(v[i] + power[N] - 1, i - last[v[i]]);
    last[v[i]] = i;
  }
  for (int j = 2; j <= n; j++) {
    int l = mn(j, j, 0) + 1;
    int r = n - 1;
    if (l <= r) {
      if (mn(1, j - 1, 0) >= l) {
        ok[j] = 1;
      }
    }
  }
  int ans = 2;
  for (int j = 2; j <= n; j++) {
    if (ok[j]) {
      ans++;
    } else {
      cout << ans << "\n";
      exit(0);
    }
  }
  if (last[n] == -1) {
    cout << ans << "\n";
  } else {
    cout << n + 2 << "\n";
  }
  return;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  power[0] = 1;
  for (int j = 1; j <= 30; j++) power[j] = power[j - 1] * 2;
  while (t--) {
    solve();
  }
  return 0;
}
