#include <bits/stdc++.h>
using namespace std;
int fa[110001], a[110001], cnt, sum[110001], cum[110001], ans, maxn, n;
;
struct node {
  int val, index;
} b[110001];
bool cmp(node a, node b) { return a.val < b.val; }
int find(int x) {
  if (fa[x] == x) return x;
  return fa[x] = find(fa[x]);
}
void merge(int a, int b) {
  a = find(a);
  b = find(b);
  cum[sum[a]]--;
  cum[sum[b]]--;
  sum[a] += sum[b];
  fa[b] = a;
  cum[sum[a]]++;
  cnt--;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i].val = a[i];
    b[i].index = i;
    fa[i] = i;
  }
  sort(b + 1, b + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    int ind = b[i].index;
    sum[ind] = 1;
    cum[sum[ind]]++;
    cnt++;
    if (ind != 1 && a[ind - 1] <= a[ind]) merge(ind - 1, ind);
    if (ind != n && a[ind + 1] <= a[ind]) merge(ind, ind + 1);
    for (; b[i].val == b[i + 1].val && i != n; i++) {
      ind = b[i].index;
      sum[ind] = 1;
      cum[sum[ind]]++;
      cnt++;
      if (ind != 1 && a[ind - 1] <= a[ind]) merge(ind - 1, ind);
      if (ind != n && a[ind + 1] <= a[ind]) merge(ind, ind + 1);
    }
    if (cnt == cum[sum[find(b[i].index)]])
      if (cnt > maxn) {
        maxn = cnt;
        ans = b[i].val + 1;
      }
  }
  printf("%d", ans);
}
