#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
set<pair<int, int> > S;
int n, ai, c = 1, compo[MAXN], len[MAXN], k = 1, mxc;
multiset<int> lens;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ai;
    S.insert(make_pair(ai, i));
  }
  for (set<pair<int, int> >::iterator it = S.begin(); it != S.end(); it++) {
    bool f = ((*it).second - 1 >= 0 && compo[(*it).second - 1] != 0);
    bool s = (*it).second + 1 < n && compo[(*it).second + 1] != 0;
    if (f && s) {
      int comb = compo[(*it).second - 1], comf = compo[(*it).second + 1];
      if (len[comf] > len[comb]) {
        lens.erase(lens.find(len[comf]));
        len[comf] += len[comb] + 1;
        lens.insert(len[comf]);
        for (int i = (*it).second + 1; compo[i] == comb && i < n; i++)
          compo[i] = comf;
      } else {
        lens.erase(lens.find(len[comb]));
        len[comb] += len[comf] + 1;
        lens.insert(len[comb]);
        for (int i = (*it).second - 1; compo[i] == comf && i >= 0; i--)
          compo[i] = comb;
      }
    } else if (f) {
      compo[(*it).second] = compo[(*it).second - 1];
      lens.erase(lens.find(len[compo[(*it).second - 1]]));
      len[compo[(*it).second - 1]]++;
      lens.insert(len[compo[(*it).second - 1]]);
    } else if (s) {
      compo[(*it).second] = compo[(*it).second + 1];
      lens.erase(lens.find(len[compo[(*it).second + 1]]));
      len[compo[(*it).second + 1]]++;
      lens.insert(len[compo[(*it).second + 1]]);
    } else {
      compo[(*it).second] = c;
      len[c] = 1;
      lens.insert(1);
      c++;
    }
    multiset<int>::iterator st = lens.begin(), en = lens.end();
    en--;
    if (*st == *en && mxc < lens.size()) {
      mxc = lens.size();
      k = (*it).first + 1;
    }
  }
  cout << k;
}
