#include <bits/stdc++.h>
using namespace std;
using tint = long long;
using ld = long double;
using pi = pair<int, int>;
using pl = pair<tint, tint>;
using vi = vector<int>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vvi = vector<vi>;
using vl = vector<tint>;
using vb = vector<bool>;
const int MOD = 1e9 + 7;
const tint mod = 998244353;
const int MX = 1e5 + 5;
const tint INF = 1e18;
const int inf = 2e9;
const ld PI = acos(ld(-1));
const ld eps = 1e-5;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
template <class T>
void remDup(vector<T>& v) {
  sort(begin(v), end(v));
  v.erase(unique(begin(v), end(v)), end(v));
}
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
bool valid(int x, int y, int n, int m) {
  return (0 <= x && x < n && 0 <= y && y < m);
}
int cdiv(int a, int b) { return a / b + ((a ^ b) > 0 && a % b); }
int fdiv(int a, int b) { return a / b - ((a ^ b) < 0 && a % b); }
void NACHO(string name = "") {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if ((int)(name).size()) {
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
  }
}
struct DSU {
  multiset<int> tams;
  int comp = 0;
  vi e;
  void init(int N) { e = vi(N, -1); }
  int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); }
  bool unite(int x, int y) {
    x = get(x), y = get(y);
    if (x == y) return 0;
    if (e[x] > e[y]) swap(x, y);
    --comp;
    tams.erase(tams.find(-e[x]));
    tams.erase(tams.find(-e[y]));
    e[x] += e[y];
    tams.insert(-e[x]);
    e[y] = x;
    return 1;
  }
};
bool has[MX];
vpi a;
int main() {
  NACHO();
  int n;
  cin >> n;
  a.resize(n);
  for (int i = (0); i < (n); ++i) cin >> a[i].first, a[i].second = i;
  DSU D;
  D.init(n);
  sort(begin(a), end(a));
  int ret = 0;
  int node = 0;
  for (int i = (0); i < (n); ++i) {
    int id = a[i].second;
    has[id] = 1;
    ++D.comp;
    D.tams.insert(1);
    if (id - 1 >= 0 && has[id - 1]) D.unite(id, id - 1);
    if (id + 1 < n && has[id + 1]) D.unite(id, id + 1);
    auto beg = D.tams.begin(), ed = --D.tams.end();
    if (*beg == *ed && D.comp > ret) {
      ret = D.comp;
      node = a[i].first + 1;
    }
  }
  cout << node << "\n";
}
