#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const double eps = 1e-8;
const double PI = acos(-1);
const long long mod = 1000000007ll;
const int inf = 1 << 30;
const int maxn = 2e5 + 5;
void err(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
int segT[maxn * 8], a[maxn];
int n;
int query(int x, int y, int idx = 1, int l = 1, int r = n) {
  if (r < x || l > y) return 123456789;
  if (x <= l && r <= y) return segT[idx];
  int mid = (l + r) / 2, lidx = idx << 1;
  return min(query(x, y, lidx, l, mid), query(x, y, lidx | 1, mid + 1, r));
}
void update(int x, int y, int idx = 1, int l = 1, int r = n) {
  if (l == r) {
    segT[idx] = y;
    return;
  }
  int mid = (l + r) / 2, lidx = idx << 1;
  if (x <= mid)
    update(x, y, lidx, l, mid);
  else
    update(x, y, lidx | 1, mid + 1, r);
  segT[idx] = min(segT[lidx], segT[lidx | 1]);
}
int la[maxn];
bool in[maxn];
void solve() {
  cin >> n;
  for (int i = 0; i < (int)(n); ++i) cin >> a[i + 1];
  memset(segT, -1, sizeof(segT));
  memset(la, -1, sizeof la);
  in[1] = true;
  bool f = false;
  for (int i = 1; i <= n; ++i) {
    f |= a[i] != 1;
    int pos = query(1, a[i] - 1);
    if (pos != -1 && pos > la[a[i]]) in[a[i]] = 1;
    update(a[i], i);
    la[a[i]] = i;
  }
  for (int i = 2; i <= n + 1; ++i) {
    int pos = query(1, i - 1);
    if (pos != -1 && pos > la[i]) in[i] = 1;
  }
  int ret = 1;
  while (f && in[ret]) ++ret;
  cout << ret;
}
int main() {
  int tc = 1;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  for (int tt = 0; tt < (int)(tc); ++tt) {
    solve();
  }
}
