#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, k, par[N], siz[N];
bool inv[N];
multiset<int> S;
struct dist {
  int val, id;
};
dist tab[N];
bool cmp(dist x, dist y) { return x.val < y.val; }
int Find(int x) {
  if (par[x] != x) par[x] = Find(par[x]);
  return par[x];
}
void Union(int x, int y) {
  x = Find(x);
  y = Find(y);
  par[x] = y;
  S.erase(S.find(siz[x]));
  S.erase(S.find(siz[y]));
  siz[y] += siz[x];
  S.insert(siz[y]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &tab[i].val);
    tab[i].id = i;
  }
  sort(tab + 1, tab + n + 1, cmp);
  int ans = 0, ile = 0;
  multiset<int>::iterator low, high;
  for (int i = 1; i <= n; i++) {
    int x = tab[i].id;
    inv[x] = 1;
    S.insert(1);
    siz[x] = 1;
    par[x] = x;
    if (inv[x - 1]) Union(x - 1, x);
    if (inv[x + 1]) Union(x + 1, x);
    low = S.begin();
    high = S.end();
    high--;
    if (*high == *low) {
      if (ile < S.size()) {
        ile = S.size();
        ans = tab[i].val + 1;
      }
    }
  }
  printf("%d", ans);
  return 0;
}
