#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
int n, l[N], r[N], coli, ansres, ansloc, mxloc, colmxloc;
bool good;
pair<int, int> a[N];
void add(int u) {
  int L = u, R = u;
  if (l[u - 1] != 0) {
    coli--;
    L = l[u - 1];
  }
  if (r[u + 1] != 0) {
    coli--;
    R = r[u + 1];
  }
  l[R] = L;
  r[L] = R;
  coli++;
  if (R - L + 1 > mxloc) {
    colmxloc = 0;
    mxloc = R - L + 1;
  }
  if (R - L + 1 == mxloc) {
    colmxloc++;
  }
  if (colmxloc == coli) {
    good = 1;
  } else {
    good = 0;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    add(a[i].second);
    if (good && coli > ansloc) {
      ansres = a[i].first + 1;
      ansloc = coli;
    }
  }
  cout << ansres;
  return 0;
}
