#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 1;
const long long int inf = 1e15;
const long long int M = 1e9 + 7;
long long int parent[N], ind[N];
multiset<long long int> s;
long long int find_set(long long int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void make_set(long long int v) {
  parent[v] = v;
  ind[v] = 1;
}
void union_sets(long long int a, long long int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (ind[a] < ind[b]) swap(a, b);
    s.erase(s.find(ind[a]));
    s.erase(s.find(ind[b]));
    s.insert(ind[a] + ind[b]);
    ind[a] += ind[b];
    parent[b] = a;
  }
}
long long int n;
pair<long long int, long long int> a[N];
long long int ans, ma, b[N];
void solve() {
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
    make_set(i);
  }
  sort(a + 1, a + 1 + n);
  for (long long int i = 1; i <= n; i++) {
    long long int x = a[i].first, pos = a[i].second;
    b[pos] = 1;
    s.insert(1);
    if (b[pos - 1] == 1) union_sets(pos, pos - 1);
    if (b[pos + 1] == 1) union_sets(pos, pos + 1);
    if (*s.begin() == *s.rbegin() and ma < s.size()) {
      ma = s.size(), ans = x + 1;
    }
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve(), cout << "\n";
  long long int x = 0;
  return 0;
}
