#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
vector<char*> tokenizer(const char* args) {
  char* token = new char[111];
  strcpy(token, args);
  token = strtok(token, ", ");
  vector<char*> v({token});
  while (token = strtok(NULL, ", ")) v.push_back(token);
  return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
  debug() << " [" << args.back() << ": " << H << "] ";
  args.pop_back();
  debugg(args, T...);
}
long long mod = 1e9 + 7;
const int MX = 0x3f3f3f3f;
int par[int(1e5) + 1], siz[int(1e5) + 1];
int find(int v) {
  if (v == par[v]) return v;
  return par[v] = find(par[v]);
}
void join(int a, int b) {
  a = find(a);
  b = find(b);
  par[b] = a;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, i, x, y;
  cin >> n;
  vector<pair<int, int> > a(n);
  vector<int> v(n + 1);
  for (i = 0; i <= n - 1; i++) cin >> a[i].first, a[i].second = i, par[i] = -1;
  sort((a).begin(), (a).end());
  int loc = 0, ans = 0, num = 0, flag;
  for (i = 0; i <= n - 1; i++) {
    par[a[i].second] = a[i].second;
    siz[a[i].second] = 1;
    flag = 0;
    num++;
    v[siz[a[i].second]]++;
    if (a[i].second && par[a[i].second - 1] != -1) {
      x = find(a[i].second);
      y = find(a[i].second - 1);
      v[siz[y]]--;
      v[siz[x]]--;
      siz[x] += siz[y];
      v[siz[x]]++;
      par[y] = x;
      flag++;
    }
    if (a[i].second < n - 1 && par[a[i].second + 1] != -1) {
      x = find(a[i].second);
      y = find(a[i].second + 1);
      v[siz[y]]--;
      v[siz[x]]--;
      siz[x] += siz[y];
      v[siz[x]]++;
      par[y] = x;
      flag++;
    }
    num -= flag;
    x = find(a[i].second);
    if (v[siz[x]] == num && num > loc) ans = a[i].first + 1, loc = num;
  }
  cout << ans;
  return 0;
}
