#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4;
int pre[N];
int a[N];
pair<int, int> b[N];
int sum[N];
int cntnum[N];
int cnt;
int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); }
void Union(int a, int b) {
  a = find(a);
  b = find(b);
  cntnum[sum[a]]--;
  cntnum[sum[b]]--;
  cnt--;
  sum[a] += sum[b];
  cntnum[sum[a]]++;
  pre[b] = a;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) scanf("%d", a + i), pre[i] = i;
  for (int i = 1; i <= n; ++i) {
    b[i].first = a[i];
    b[i].second = i;
  }
  sort(b + 1, b + n + 1);
  cnt = 0;
  int mx = 0;
  int ans;
  for (int i = 1; i <= n; ++i) {
    int val = b[i].first;
    int ind = b[i].second;
    cnt++;
    sum[ind] = 1;
    cntnum[sum[ind]]++;
    if (ind != 1 && a[ind - 1] < a[ind]) {
      Union(ind, ind - 1);
    }
    if (ind != n && a[ind + 1] < a[ind]) {
      Union(ind, ind + 1);
    }
    if (cnt == cntnum[sum[ind]]) {
      if (cnt > mx) {
        ans = val + 1;
        mx = cnt;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
