#include <bits/stdc++.h>
using namespace std;
long long parent[100005], sz[100005], vis[100005], cnt = 0;
map<long long, long long> segment;
long long root(long long x) {
  if (parent[x] == x) return x;
  return parent[x] = root(parent[x]);
}
void merge(long long u, long long v) {
  u = root(u), v = root(v);
  if (u == v) return;
  cnt--;
  segment[sz[u]]--;
  segment[sz[v]]--;
  if (!segment[sz[u]]) segment.erase(sz[u]);
  if (!segment[sz[v]]) segment.erase(sz[v]);
  segment[sz[u] + sz[v]]++;
  if (sz[u] > sz[v]) {
    parent[v] = u;
    sz[u] += sz[v];
  } else {
    parent[u] = v;
    sz[v] += sz[u];
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t, n, i, j, k;
  cin >> n;
  vector<pair<long long, long long>> v(n);
  for (i = 0; i < n; i++) {
    cin >> v[i].first;
    v[i].second = i + 1;
    parent[i + 1] = 1 + i;
    sz[i + 1] = 1;
    vis[i + 1] = 0;
  }
  sort(v.begin(), v.end());
  long long ans = 0, val = 0;
  for (i = 0; i < n; i++) {
    k = v[i].second;
    cnt++;
    vis[k] = 1;
    segment[1]++;
    if (vis[k - 1]) {
      merge(k, k - 1);
    }
    if (vis[k + 1]) {
      merge(k, k + 1);
    }
    if (segment.size() == 1 && cnt > ans) {
      ans = cnt;
      val = v[i].first + 1;
    }
  }
  cout << val;
}
