#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
multiset<int> ms;
int loc = 0, k = 0;
int par[100022], sz[100022], is[100022];
int find(int p) {
  if (par[p] == p) return p;
  return par[p] = find(par[p]);
}
vector<pair<int, int> > v;
int main() {
  int i, n;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    int a;
    par[i] = i;
    sz[i] = 1;
    is[i] = 0;
    scanf("%d", &a);
    v.push_back(make_pair(a, i));
  }
  sort(v.begin(), v.end());
  for (i = 0; i < n; i++) {
    int ind = v[i].second;
    is[ind] = 1;
    mp[1]++;
    ms.insert(1);
    if (is[ind - 1] == 1) {
      int lp = find(ind - 1), rp = find(ind);
      mp[sz[lp]]--;
      mp[sz[rp]]--;
      ms.erase(ms.find(sz[lp]));
      ms.erase(ms.find(sz[rp]));
      sz[lp] += sz[rp];
      par[rp] = lp;
      mp[sz[lp]]++;
      ms.insert(sz[lp]);
    }
    if (is[ind + 1] == 1) {
      int lp = find(ind), rp = find(ind + 1);
      mp[sz[lp]]--;
      mp[sz[rp]]--;
      ms.erase(ms.find(sz[lp]));
      ms.erase(ms.find(sz[rp]));
      sz[lp] += sz[rp];
      par[rp] = lp;
      mp[sz[lp]]++;
      ms.insert(sz[lp]);
    }
    int pp = find(ind), tot = ms.size();
    if (tot == mp[sz[pp]]) {
      if (tot > loc) {
        loc = tot;
        k = v[i].first + 1;
      }
    }
  }
  cout << k << endl;
  return 0;
}
