#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1e9 + 7;
long long int INF = 1e18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i, j, k = 0, l = 0, r = 0, m = 0, n, x, y, z, a, b, p = 0,
                      cnt = 0, cnt1 = 0, low, mid, high, ans = 0, c = 0,
                      maxi = -1, mini = INF, t, q, ind;
  string s, s1;
  cin >> n;
  vector<pair<long long int, long long int> > A;
  for (i = 0; i < n; i++) {
    cin >> x;
    A.push_back({x, i});
  }
  sort(A.begin(), A.end());
  long long int L[n];
  long long int R[n];
  for (i = 0; i < n; i++) {
    L[i] = -1;
    R[i] = -1;
  }
  for (i = 0; i < n; i++) {
    k = A[i].second;
    l = k;
    r = k;
    if (k != 0 && L[k - 1] != -1) {
      c--;
      l = L[k - 1];
    }
    if (R[k + 1] != -1 && k != n - 1) {
      c--;
      r = R[k + 1];
    }
    c++;
    L[r] = l;
    R[l] = r;
    if (r - l + 1 > maxi) {
      maxi = r - l + 1;
      cnt1 = 0;
    }
    if (r - l + 1 == maxi) cnt1++;
    if (c == cnt1 && c > m) {
      m = c;
      ans = A[i].first + 1;
    }
  }
  cout << ans;
}
