#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int arr[maxn], pos[maxn];
int revmap[maxn], n, lens[maxn], lene[maxn];
vector<int> seq;
int ptr;
map<int, int> m;
int mapper(int num) {
  int val = m[num];
  if (val != 0) return val;
  m[num] = ++ptr;
  revmap[ptr] = num;
  return ptr;
}
multiset<int> s;
bool same() {
  if (s.size() == 0) return false;
  multiset<int>::iterator it = s.begin();
  int val = *it;
  it = s.end();
  it--;
  if (val == *it)
    return true;
  else
    return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    seq.push_back(arr[i]);
  }
  sort(seq.begin(), seq.end());
  for (auto u : seq) mapper(u);
  for (int i = 1; i <= n; i++) {
    arr[i] = mapper(arr[i]);
    pos[arr[i]] = i;
  }
  int ans = 2, anslen = 0;
  for (int i = 2; i <= n; i++) {
    int first = pos[i - 1];
    int l = first, r = first;
    if (first > 1 && arr[first - 1] < (i - 1))
      l = first - 1 - lene[first - 1] + 1;
    if (first < n && arr[first + 1] < (i - 1))
      r = first + 1 + lens[first + 1] - 1;
    if (lens[l] != 0) s.erase(s.find(lens[l]));
    if (lene[r] != 0) s.erase(s.find(lene[r]));
    lens[l] = r - l + 1;
    lene[r] = r - l + 1;
    s.insert(lens[l]);
    if (same()) {
      if (s.size() > anslen) {
        ans = i;
        anslen = s.size();
      }
    }
  }
  if (ans == 0)
    cout << 0;
  else {
    cout << revmap[ans - 1] + 1;
  }
  return 0;
}
