#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 6;
long long par[MAXN], a[MAXN], n;
long long sz[MAXN], maxsz = 0, brmaxsz = 0, br = 0;
void join(long long p, long long q) {
  if (p == q) {
    return;
  }
  br--;
  if (sz[p] == maxsz) brmaxsz--;
  if (sz[q] == maxsz) brmaxsz--;
  if (sz[p] > sz[q]) {
    par[q] = p;
    sz[p] += sz[q];
    if (sz[p] > maxsz) {
      maxsz = sz[p];
      brmaxsz = 0;
    }
    if (sz[p] == maxsz) {
      brmaxsz++;
    }
  } else {
    par[p] = q;
    sz[q] += sz[p];
    if (sz[q] > maxsz) {
      maxsz = sz[q];
      brmaxsz = 0;
    }
    if (sz[q] == maxsz) {
      brmaxsz++;
    }
  }
}
long long getRoot(long long u) {
  if (u == par[u]) return u;
  return par[u] = getRoot(par[u]);
}
vector<pair<long long, long long> > v;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    par[i] = i;
    sz[i] = 1;
    v.push_back({a[i], i});
  }
  sort(v.begin(), v.end());
  int ansbr = -1, ansk = -1;
  for (int i = 0; i < n; i++) {
    int a1 = v[i].first;
    int a2 = v[i].second;
    br++;
    if (maxsz == 0) {
      maxsz = 1;
      brmaxsz = 0;
    }
    if (maxsz == 1) {
      brmaxsz++;
    }
    if (a2 != 0 && a[a2 - 1] <= a1) {
      join(a2, getRoot(a2 - 1));
    }
    if (a2 != n - 1 && a[a2 + 1] <= a1) {
      join(getRoot(a2), getRoot(a2 + 1));
    }
    if (brmaxsz == br) {
      if (br > ansbr) {
        ansbr = br;
        ansk = v[i].first + 1;
      }
    }
  }
  cout << ansk << endl;
  return 0;
}
