#include <bits/stdc++.h>
const int MaxSize = 20;
char buf[1 << MaxSize], *p1, *p2;
template <class T>
inline void in(T &x) {
  x = 0;
  register bool f = 0;
  register char c =
      ((p1 == p2) ? (p2 = buf + fread(p1 = buf, 1, 1 << MaxSize, stdin),
                     p1 == p2 ? EOF : *p1++)
                  : *p1++);
  while (c < 47 || c > 58) {
    f |= (c == '-'),
        c = ((p1 == p2) ? (p2 = buf + fread(p1 = buf, 1, 1 << MaxSize, stdin),
                           p1 == p2 ? EOF : *p1++)
                        : *p1++);
  }
  while (c <= 58 && c >= 47) {
    x = (x << 3) + (x << 1) + (c & 15),
    c = ((p1 == p2) ? (p2 = buf + fread(p1 = buf, 1, 1 << MaxSize, stdin),
                       p1 == p2 ? EOF : *p1++)
                    : *p1++);
  }
  x = f ? -x : x;
}
const int MaxN = 1e5 + 5;
int n, cnt, ans, maxi, a[MaxN], father[MaxN], sum[MaxN], res[MaxN];
struct Node {
  int val, pos;
  inline bool operator<(const Node &tmp) const { return val < tmp.val; }
} b[MaxN];
int Find(int x) {
  return (father[x] == x) ? father[x] : father[x] = Find(father[x]);
}
inline void Union(int x, int y) {
  int fx = Find(x), fy = Find(y);
  res[sum[fx]]--, res[sum[fy]]--;
  sum[fx] += sum[fy];
  father[fy] = fx;
  res[sum[fx]]++, cnt--;
  return;
  return;
}
int main() {
  in(n);
  for (register int i = 1; i <= n; ++i) {
    in(a[i]), father[i] = i;
    b[i].val = a[i], b[i].pos = i;
  }
  std::sort(b + 1, b + n + 1);
  for (register int i = 1; i <= n; ++i) {
    int pos = b[i].pos;
    sum[pos] = 1, res[sum[pos]]++;
    cnt++;
    if (pos != 1 && a[pos - 1] <= a[pos]) {
      Union(pos - 1, pos);
    }
    if (pos != n && a[pos + 1] <= a[pos]) {
      Union(pos, pos + 1);
    }
    for (; b[i].val == b[i + 1].val && i != n; ++i) {
      pos = b[i].pos, sum[pos] = 1;
      res[sum[pos]]++, cnt++;
      if (pos != 1 && a[pos - 1] <= a[pos]) {
        Union(pos - 1, pos);
      }
      if (pos != n && a[pos + 1] <= a[pos]) {
        Union(pos, pos + 1);
      }
    }
    if (cnt == res[sum[Find(b[i].pos)]] && cnt > maxi) {
      maxi = cnt, ans = b[i].val + 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}
