#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int fa[maxn], sum[maxn], m[maxn];
int a[maxn], r[maxn], n;
int ansk = 0, anssum = 0, cntsum = 0;
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void uni(int x, int y) {
  int fx = find(x);
  int fy = find(y);
  fa[fy] = fx;
  m[sum[fy]]--;
  m[sum[fx]]--;
  sum[fx] += sum[fy];
  m[sum[fx]]++;
  cntsum--;
  return;
}
int cmp(int i, int j) { return a[i] < a[j]; }
int main() {
  memset(fa, -1, sizeof(fa));
  memset(sum, 0, sizeof(sum));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  for (int i = 0; i < n; i++) r[i] = i;
  sort(r, r + n, cmp);
  for (int i = 0; i < n; i++) {
    int x = r[i];
    fa[x] = x;
    sum[x] = 1;
    m[1]++;
    cntsum++;
    if (x - 1 >= 0 && fa[x - 1] != -1) {
      uni(x, x - 1);
    }
    if (x + 1 < n && fa[x + 1] != -1) {
      uni(x, x + 1);
    }
    int fx = find(x);
    if (m[sum[fx]] == cntsum && cntsum > anssum)
      ansk = a[x] + 1, anssum = cntsum;
  }
  printf("%d\n", ansk);
  return 0;
}
