#include <bits/stdc++.h>
using namespace std;
int fa[110000 + 1], a[110000 + 1], cnt, sum[110000 + 1], cntsum[110000 + 1];
struct node {
  int val, index;
} b[110000 + 1];
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);
  cntsum[sum[a]]--;
  cntsum[sum[b]]--;
  sum[a] += sum[b];
  fa[b] = a;
  cntsum[sum[a]]++;
  cnt--;
}
int ans, maxn;
int main() {
  int n;
  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 pos = b[i].index;
    sum[pos] = 1;
    cntsum[sum[pos]]++;
    cnt++;
    if (pos != 1 && a[pos - 1] <= a[pos]) merge(pos - 1, pos);
    if (pos != n && a[pos + 1] <= a[pos]) merge(pos, pos + 1);
    for (; b[i].val == b[i + 1].val && i != n; i++) {
      pos = b[i].index;
      sum[pos] = 1;
      cntsum[sum[pos]]++;
      cnt++;
      if (pos != 1 && a[pos - 1] <= a[pos]) merge(pos - 1, pos);
      if (pos != n && a[pos + 1] <= a[pos]) merge(pos, pos + 1);
    }
    if (cnt == cntsum[sum[find(b[i].index)]])
      if (cnt > maxn) {
        maxn = cnt;
        ans = b[i].val + 1;
      }
  }
  printf("%d", ans);
  return 0;
}
