#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, res1, res2;
struct Data {
  int data, pos;
} a[N];
bool cmp(const Data a, const Data b) { return a.data < b.data; }
struct DSU {
  int fa[N], size[N];
  multiset<int> bag;
  int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
  void merge(int u, int v) {
    int fu = find(u), fv = find(v);
    if (fu != fv) {
      bag.erase(bag.find(size[fu]));
      bag.erase(bag.find(size[fv]));
      fa[fv] = fu, size[fu] += size[fv];
      bag.insert(size[fu]);
    }
  }
} d;
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i].data);
    a[i].pos = i;
  }
  sort(a + 1, a + 1 + n, cmp);
  for (int i = 1; i <= n; ++i) {
    d.fa[a[i].pos] = a[i].pos;
    d.size[a[i].pos] = 1, d.bag.insert(1);
    if (a[i].pos > 1 && d.fa[a[i].pos - 1]) d.merge(a[i].pos, a[i].pos - 1);
    if (a[i].pos < n && d.fa[a[i].pos + 1]) d.merge(a[i].pos, a[i].pos + 1);
    set<int>::iterator tmp1 = d.bag.begin(), tmp2 = d.bag.end();
    tmp2--;
    if (*tmp1 == *tmp2) {
      if ((int)d.bag.size() > res1) res1 = d.bag.size(), res2 = a[i].data + 1;
    }
  }
  return printf("%d\n", res2), 0;
}
