#include <bits/stdc++.h>
using namespace std;
const long long int md = 1e9 + 7;
const long long int N = 100005;
long long int dsu[N], sz[N];
pair<long long int, long long int> a[N];
map<long long int, long long int> m;
long long int root(long long int u) {
  while (u != dsu[u]) u = dsu[u];
  return u;
}
bool uni(long long int u, long long int v) {
  u = root(u), v = root(v);
  if (u == v) return 0;
  m[sz[u]]--;
  if (m[sz[u]] == 0) m.erase(sz[u]);
  m[sz[v]]--;
  if (m[sz[v]] == 0) m.erase(sz[v]);
  m[sz[u] + sz[v]]++;
  if (sz[u] > sz[v]) {
    dsu[v] = u;
    sz[u] += sz[v];
  } else {
    dsu[u] = v;
    sz[v] += sz[u];
  }
  return 1;
}
bool active[N];
signed main() {
  ios::sync_with_stdio(0);
  long long int n;
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
    dsu[i] = i;
    sz[i] = 1;
  }
  sort(a + 1, a + n + 1);
  long long int maxi = 0;
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    long long int v = a[i].first;
    while (a[i].first == v) {
      active[a[i].second] = 1;
      m[1]++;
      if (a[i].second > 1 && active[a[i].second - 1])
        uni(a[i].second - 1, a[i].second);
      if (a[i].second < n && active[a[i].second + 1])
        uni(a[i].second, a[i].second + 1);
      i++;
    }
    i--;
    auto it = m.begin();
    if (m.size() == 1 && maxi < it->second) {
      ans = a[i].first;
      maxi = it->second;
    }
  }
  cout << ans + 1;
  return 0;
}
