#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, oo = inf;
inline long long read() {
  register long long x = 0;
  char f = 0;
  register char c = getchar();
  for (; !isdigit(c); c = getchar()) f |= (c == '-');
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  return f ? -x : x;
}
inline double readdb() {
  register double x = 0, p = 0.1;
  register char f = 0, c = getchar();
  for (; !isdigit(c); c = getchar()) f |= (c == '-');
  for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  if (c == '.')
    for (c = getchar(); isdigit(c); c = getchar(), p /= 10)
      x = x + (c ^ 48) * p;
  return f ? -x : x;
}
inline void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
inline void writeln(long long x, char c, long long y) {
  write(x);
  putchar(c);
  writeln(y);
}
inline void writeln(long long x, char c, long long y, char d, long long z) {
  write(x);
  putchar(c);
  write(y);
  putchar(d);
  writeln(z);
}
int a[110000], to[110000], ss[110000], sum[110000], fa[110000];
int all, ansx, ansk, n;
bool cmp(int x, int y) { return a[x] < a[y]; }
int gf(int x) {
  if (fa[x] != x) return gf(fa[x]);
  return fa[x];
}
void merge(int x, int y) {
  x = gf(x);
  y = gf(y);
  if (!y) return;
  ss[sum[x]] -= 1;
  ss[sum[y]] -= 1;
  sum[x] += sum[y];
  fa[y] = x;
  ss[sum[x]] += 1;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= n; i++) to[i] = i;
  sort(to + 1, to + n + 1, cmp);
  ansx = 0;
  ansk = 0;
  for (int i = 1; i <= n; i++) {
    sum[to[i]] = 1;
    all += 1;
    ss[1] += 1;
    fa[to[i]] = to[i];
    merge(to[i], to[i] - 1);
    merge(to[i], to[i] + 1);
    if ((i == n || a[to[i] + 1] != a[to[i]]) &&
        all == ss[sum[gf(to[i])]] * sum[gf(to[i])]) {
      int x = ss[sum[gf(to[i])]], k = a[to[i]] + 1;
      if (x > ansx) ansx = x, ansk = k;
    }
  }
  printf("%d\n", ansk);
}
