#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n;
struct dsu {
  int parent[maxn];
  int rank[maxn];
  int size[maxn];
  map<int, int> m;
  dsu() {
    for (int i = 0; i < n; i++) {
      parent[i] = i;
      rank[i] = 0;
      size[i] = 1;
    }
  }
  int getParent(int a) {
    return (parent[a] == a ? a : parent[a] = getParent(parent[a]));
  }
  void join(int a, int b) {
    int p1 = getParent(a);
    int p2 = getParent(b);
    if (p1 != p2) {
      if (rank[p1] < rank[p2]) swap(p1, p2);
      if (rank[p1] > rank[p2])
        parent[p2] = p1;
      else
        parent[p2] = p1, rank[p1]++;
      m[size[p2]]--;
      m[size[p1]]--;
      if (m[size[p2]] == 0) {
        m.erase(size[p2]);
      }
      if (m[size[p1]] == 0) {
        m.erase(size[p1]);
      }
      size[p1] += size[p2];
      m[size[p1]]++;
    }
  }
};
int main() {
  cin >> n;
  int a[n];
  vector<pair<int, int> > sk(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sk[i] = make_pair(a[i], i);
  }
  sort(sk.begin(), sk.end());
  for (int i = 0; i < n; i++) {
    a[sk[i].second] = i + 1;
  }
  dsu d;
  bool did[maxn] = {};
  int days = 0, ans = sk[n - 1].first;
  for (auto p : sk) {
    int i = p.second;
    d.m[1]++;
    did[i] = 1;
    if (i > 0 && did[i - 1]) d.join(i, i - 1);
    if (i < n - 1 && did[i + 1]) d.join(i, i + 1);
    if (d.m.size() == 1) {
      for (auto b : d.m) {
        if (b.second > days) {
          days = b.second;
          ans = p.first;
        }
      }
    }
  }
  cout << ans + 1 << endl;
}
