#include <bits/stdc++.h>
using namespace std;
const int N = 100007;
int n, a[N], ans;
priority_queue<pair<int, int> > q;
set<pair<int, int> > intervals;
multiset<int> sizes;
int locations_ans;
void handle(int idx) {
  set<pair<int, int> >::iterator it =
      intervals.upper_bound(make_pair(idx, 10000007));
  --it;
  pair<int, int> curr = *it;
  sizes.erase(sizes.find(curr.second - curr.first + 1));
  intervals.erase(curr);
  if (curr.first <= idx - 1) {
    sizes.insert(idx - 1 - curr.first + 1);
    intervals.insert(make_pair(curr.first, idx - 1));
  }
  if (idx + 1 <= curr.second) {
    sizes.insert(curr.second - (idx + 1) + 1);
    intervals.insert(make_pair(idx + 1, curr.second));
  }
}
int first() { return *sizes.begin(); }
int last() {
  multiset<int>::iterator it = sizes.end();
  --it;
  return *it;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    q.push(make_pair(a[i], i));
    ans = max(ans, a[i]);
  }
  ++ans;
  locations_ans = 1;
  intervals.insert(make_pair(1, n));
  sizes.insert(n);
  while (!q.empty()) {
    pair<int, int> curr = q.top();
    while (!q.empty() && q.top().first == curr.first) {
      handle(q.top().second);
      q.pop();
    }
    if (!sizes.empty())
      if (first() == last()) {
        int curr_locations = (int)(sizes.size());
        int curr_ans = q.top().first + 1;
        if (curr_locations > locations_ans ||
            (curr_locations == locations_ans && curr_ans < ans)) {
          locations_ans = curr_locations;
          ans = curr_ans;
        }
      }
  }
  printf("%d\n", ans);
  return 0;
}
