#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const long long N = 1e5 + 10;
long long par[N];
long long sz[N];
bool done[N];
long long comp;
multiset<long long> s;
long long root(long long x) {
  while (x != par[x]) x = par[x];
  return x;
}
void merge(long long x, long long y) {
  done[x] = done[y] = true;
  x = root(x);
  y = root(y);
  s.erase(s.find(sz[x]));
  s.erase(s.find(sz[y]));
  --comp;
  if (sz[x] < sz[y]) {
    par[x] = y;
    sz[y] += sz[x];
    s.insert(sz[y]);
  } else {
    par[y] = x;
    sz[x] += sz[y];
    s.insert(sz[x]);
  }
}
void init(long long idx) {
  par[idx] = idx;
  sz[idx] = 1;
  s.insert(1);
  ++comp;
}
void solve() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> a(n);
  for (long long i = 0; i < n; ++i) cin >> a[i].first, a[i].second = i + 1;
  sort(a.begin(), a.end());
  long long loc = 0;
  long long ans = 0;
  for (long long i = 0; i < n; ++i) {
    long long idx = a[i].second;
    long long val = a[i].first;
    init(idx);
    if (par[idx - 1]) merge(idx, idx - 1);
    if (par[idx + 1]) merge(idx, idx + 1);
    if (*s.begin() == *s.rbegin() && comp > loc) {
      ans = val + 1;
      loc = comp;
    }
  }
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t = 1;
  while (t--) solve();
}
