#include <bits/stdc++.h>
using namespace std;
class DSU {
 private:
  vector<int> par, sz;
  vector<bool> inactive;
  multiset<int> sizes;
  int cnt, n;

 public:
  DSU(int _n) : n(_n) {
    sz.assign(n + 1, 0);
    inactive.assign(n + 1, 1);
    par.assign(n + 1, 0);
    cnt = 0;
  }
  void set_active(int a) {
    inactive[a] = 0;
    sz[a] = 1;
    par[a] = a;
    cnt++;
    sizes.insert(sz[a]);
  }
  int find_parent(int a) {
    if (a == par[a]) return a;
    return par[a] = find_parent(par[a]);
  }
  bool union_sets(int a, int b) {
    if (inactive[a] || inactive[b]) return 0;
    a = find_parent(a);
    b = find_parent(b);
    if (a != b) {
      par[b] = a;
      sizes.erase(sizes.lower_bound(sz[a]));
      sizes.erase(sizes.lower_bound(sz[b]));
      sz[a] += sz[b];
      sizes.insert(sz[a]);
      --cnt;
      return 1;
    }
    return 0;
  }
  int get_ans() {
    if (*sizes.begin() != *sizes.rbegin()) return -1;
    return cnt;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.emplace_back(x, i + 1);
  }
  sort(v.begin(), v.end());
  DSU dsu(n);
  int ans_size = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    auto &[val, ind] = v[i];
    dsu.set_active(ind);
    if (ind - 1 > 0) {
      dsu.union_sets(ind, ind - 1);
    }
    if (ind + 1 <= n) {
      dsu.union_sets(ind, ind + 1);
    }
    int res = dsu.get_ans();
    if (res > ans_size) {
      ans_size = res;
      ans = val + 1;
    }
  }
  cout << ans;
}
