#include <bits/stdc++.h>
using namespace std;
int n, a[100010];
int id[100010];
set<int> s;
multiset<int> s2;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i), id[i] = i;
  sort(id + 1, id + 1 + n, [](int x, int y) { return a[x] > a[y]; });
  s.insert(0), s.insert(n + 1);
  int ans = a[id[1]] + 1, cnt = 1;
  s2.insert(n);
  for (int i = 1; i < n; i++) {
    int pos = id[i];
    auto ite = s.lower_bound(pos);
    int nxt = *ite, lst = *prev(ite);
    s.insert(pos);
    s2.erase(s2.lower_bound(nxt - lst - 1));
    if (pos != nxt - 1) s2.insert(nxt - pos - 1);
    if (pos - 1 != lst) s2.insert(pos - lst - 1);
    if (*s2.begin() == *prev(s2.end())) {
      int cur = s2.size();
      if (cur >= cnt) cnt = cur, ans = a[id[i + 1]] + 1;
    }
  }
  cout << ans << endl;
}
