#include <bits/stdc++.h>
using namespace std;
int gcd(int f, int s) {
  if (s == 0)
    return f;
  else
    return gcd(s, f % s);
}
int const N = 100300;
long long const mod = 1000 * 1000 * 1000 + 7;
int n, arr[N], seg[4 * N];
bool lazy[4 * N];
map<int, int> frq;
set<int> currInt;
pair<int, int> sortedArray[N];
void fix(int node, int start, int end) {
  if (!lazy[node]) return;
  if (start != end) {
    seg[node * 2] = seg[node * 2 + 1] = seg[node];
    lazy[node * 2] = lazy[node * 2 + 1] = 1;
    seg[node] = -1;
  }
  lazy[node] = 0;
}
int get(int node, int start, int end, int ind) {
  fix(node, start, end);
  if (start == end)
    return seg[node];
  else {
    int mid = (start + end) / 2;
    if (ind <= mid)
      return get(node * 2, start, mid, ind);
    else
      return get(node * 2 + 1, mid + 1, end, ind);
  }
}
void up(int node, int start, int end, int left, int right, int val) {
  fix(node, start, end);
  if (start > right || end < left) return;
  if (start >= left && end <= right) {
    seg[node] = val;
    lazy[node] = 1;
    return;
  }
  int mid = (start + end) / 2;
  up(node * 2, start, mid, left, right, val);
  up(node * 2 + 1, mid + 1, end, left, right, val);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", arr + i);
    sortedArray[i].first = arr[i];
    sortedArray[i].second = i;
  }
  sort(sortedArray, sortedArray + n + 1);
  sortedArray[n + 1].first = sortedArray[n].first + 1;
  memset(seg, -1, sizeof seg);
  int intCounter = 0, res = -1, ans;
  for (int i = 1; i <= n; i++) {
    int orginalIndex = sortedArray[i].second;
    int leftVal = -1, rightVal = -1;
    if (orginalIndex != 1) leftVal = get(1, 1, n, orginalIndex - 1);
    if (orginalIndex != n) rightVal = get(1, 1, n, orginalIndex + 1);
    int left = orginalIndex, right = orginalIndex, VAL = 1;
    if (leftVal != -1) {
      left = orginalIndex - leftVal;
      VAL += leftVal;
      frq[leftVal]--;
      if (frq[leftVal] == 0) currInt.erase(leftVal);
    }
    if (rightVal != -1) {
      right = orginalIndex + rightVal;
      VAL += rightVal;
      frq[rightVal]--;
      if (frq[rightVal] == 0) currInt.erase(rightVal);
    }
    up(1, 1, n, left, right, VAL);
    frq[VAL]++;
    if (frq[VAL] == 1) currInt.insert(VAL);
    if (currInt.size() == 1) {
      if (frq[VAL] > res) {
        res = frq[VAL];
        ans = sortedArray[i].first + 1;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
