#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:20123456")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int N = (int)1e6 + 100;
const int mod = (int)1e9 + 7;
const int inf = INT_MAX;
const long long ll_inf = LLONG_MAX;
const long double PI = acos((long double)-1.0);
const long double eps = 1e-6;
int n;
int parent[N], sz[N];
vector<pair<int, int> > a;
multiset<int> dsu;
int dsu_get(int v) {
  return (v == parent[v] ? v : parent[v] = dsu_get(parent[v]));
}
void dsu_merge(int a, int b) {
  a = dsu_get(a), b = dsu_get(b);
  if (sz[a] > sz[b]) swap(a, b);
  sz[a] += sz[b];
  parent[b] = a;
}
void dsu_add(int i) {
  sz[i] = 1;
  parent[i] = i;
  if (i + 1 < n && parent[i + 1] != -1) {
    dsu.erase(dsu.find(sz[dsu_get(i + 1)]));
    dsu_merge(i, i + 1);
  }
  if (i - 1 >= 0 && parent[i - 1] != -1) {
    dsu.erase(dsu.find(sz[dsu_get(i - 1)]));
    dsu_merge(i, i - 1);
  }
  dsu.insert(sz[dsu_get(i)]);
}
void solve() {
  memset(parent, -1, sizeof parent);
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i) cin >> a[i].first, a[i].second = i;
  int mxsz = 0, ans = inf;
  sort((a).begin(), (a).end());
  for (int i = 0; i < n; ++i) {
    dsu_add(a[i].second);
    if (!dsu.empty() && *dsu.begin() == *dsu.rbegin()) {
      if ((int)dsu.size() > mxsz) {
        mxsz = dsu.size();
        ans = a[i].first + 1;
      }
      if ((int)dsu.size() == mxsz) {
        ans = min(ans, a[i].first + 1);
      }
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int T = 1;
  for (; T; --T) solve();
  return 0;
}
