#include <bits/stdc++.h>
using namespace std;
vector<long long> v, p, r, rr;
vector<int> nu;
vector<bool> v2;
vector<pair<long long, long long>> v1;
int find(int a) {
  if (a == p[a]) {
    return a;
  }
  return p[a] = find(p[a]);
}
void unio(int a, int b) {
  a = find(a);
  b = find(b);
  if (r[a] < r[b]) {
    swap(a, b);
  }
  rr[r[a]]--;
  r[a] += r[b];
  rr[r[a]]++;
  rr[r[b]]--;
  r[b] = 0;
  p[b] = a;
}
int main() {
  long long n, q = 0, maxk = 0, maxq = 0;
  cin >> n;
  v.resize(n);
  p.resize(n);
  rr.resize(n + 1);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    cin >> v[i];
  }
  r.resize(n, 0);
  for (int i = 0; i < n; i++) {
    v1.push_back({v[i], i});
  }
  sort(v1.begin(), v1.end());
  v2.resize(n, false);
  for (int i = 0; i < n; i++) {
    int j = v1[i].second;
    v2[j] = true;
    r[j] = 1;
    rr[1]++;
    q++;
    if (j > 0) {
      if (v2[j - 1] == true) {
        unio(j, j - 1);
        q--;
      }
    }
    if (j < n - 1) {
      if (v2[j + 1] == true) {
        unio(j, j + 1);
        q--;
      }
    }
    if (rr[r[p[find(j)]]] == q) {
      if (q > maxq) {
        maxk = v1[i].first;
        maxq = q;
      }
    }
  }
  cout << maxk + 1;
}
