#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
const long long MOD = 1e9 + 7;
int n, f[N];
set<pair<int, int> > s;
int main() {
  scanf("%d", &n);
  vector<int> a(n);
  unordered_map<int, vector<int> > idx;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    idx[a[i]].push_back(i);
  }
  sort(a.begin(), a.end());
  a.resize(unique(a.begin(), a.end()) - a.begin());
  auto last = s.end();
  int ans = 2e9, mx = -1;
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < idx[a[i]].size(); j++) {
      pair<int, int> c = make_pair(idx[a[i]][j], idx[a[i]][j]);
      auto it = s.lower_bound(c);
      if (it != s.end())
        --it;
      else
        it = last;
      if (it != s.end() && it->second == c.first - 1) {
        f[it->second - it->first + 1]--;
        c.first = it->first;
        s.erase(it);
      }
      it = s.lower_bound(c);
      if (it != s.end() && it->first == c.second + 1) {
        f[it->second - it->first + 1]--;
        c.second = it->second;
        s.erase(it);
      }
      f[c.second - c.first + 1]++;
      s.insert(c);
      if (s.upper_bound(c) == s.end()) last = s.find(c);
      if (s.empty()) continue;
      int x = s.begin()->first, y = s.begin()->second;
      if (f[y - x + 1] == s.size() && (int)s.size() > mx) {
        mx = s.size();
        ans = a[i] + 1;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
