#include <bits/stdc++.h>
using namespace std;
int N;
int A[100005];
set<int> Ai;
map<int, vector<int> > idx;
int Cnt[100005];
int Parent[100005], Size[100005];
int Find(int U) {
  if (Parent[U] == U) return U;
  return Parent[U] = Find(Parent[U]);
}
void Union(int U, int V) {
  U = Find(U), V = Find(V);
  if (U != V) {
    Parent[U] = V;
    Size[V] += Size[U];
    Size[U] = 0;
  }
}
void Add(int X) {
  Size[X] = 1;
  Cnt[Size[X]]++;
  if (X != 0) {
    int X1 = Find(X - 1);
    if (Size[X1]) {
      Cnt[Size[X]]--;
      Union(X1, X);
      Cnt[Size[X]]++;
    }
  }
  if (X != N - 1) {
    int X1 = Find(X + 1);
    if (Size[X1]) {
      Cnt[Size[X]]--;
      Union(X1, X);
      Cnt[Size[X]]++;
    }
  }
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    Ai.insert(A[i]);
    Parent[i] = i, Size[i] = 0;
    idx[A[i]].push_back(i);
  }
  int Added = 0, MaxSegs = 0, K, S;
  for (auto i : Ai) {
    for (auto j : idx[i]) Add(j), Added++;
    S = Find(idx[i][0]);
    if (Cnt[Size[S]] == Added / Size[S] && (Added % Size[S] == 0))
      if (MaxSegs < Cnt[Size[S]]) {
        MaxSegs = Cnt[Size[S]];
        K = i + 1;
      }
  }
  printf("%d\n", K);
}
