#include <bits/stdc++.h>
using namespace std;
void erase(map<long long int, long long int>& data, long long int x) {
  data[x]--;
  if (data[x] == 0) data.erase(x);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, ans, cnt = 0;
  cin >> n;
  vector<long long int> arr;
  vector<pair<long long int, long long int> > A;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    arr.push_back(x);
    A.push_back({x, i});
  }
  sort((A).begin(), (A).end(), greater<pair<long long int, long long int> >());
  map<long long int, long long int> X, data;
  X[0] = n - 1;
  data[n]++;
  ans = A[0].first + 1;
  for (long long int i = 0; i < n - 1; i++) {
    map<long long int, long long int>::iterator itr =
        X.upper_bound(A[i].second);
    itr--;
    long long int pre = itr->first;
    long long int next = itr->second;
    long long int curr = A[i].second;
    erase(data, next - pre + 1);
    X.erase(pre);
    if (curr - 1 - pre >= 0) {
      X[pre] = curr - 1;
      data[(curr - 1) - (pre) + 1]++;
    }
    if (next - (curr + 1) >= 0) {
      X[curr + 1] = next;
      data[(next) - (curr + 1) + 1]++;
    }
    if (A[i + 1].first != A[i].first && data.size() == 1) {
      if (X.size() >= cnt) {
        cnt = X.size();
        ans = A[i + 1].first + 1;
      }
    }
  }
  cout << ans;
}
