#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
int a[maxn];
pair<int, int> magicvalue[maxn];
int father[maxn];
int cnt[maxn];
int num[maxn];
int tot = 0;
int findfather(int x) {
  return (x == father[x]) ? x : (father[x] = findfather(father[x]));
}
void merge(int a, int b) {
  int x = findfather(a);
  int y = findfather(b);
  cnt[num[x]]--;
  cnt[num[y]]--;
  num[x] += num[y];
  father[y] = x;
  cnt[num[x]]++;
  tot--;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  int ans = 0;
  int maxnum = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    magicvalue[i] = make_pair(a[i], i);
    father[i] = i;
    num[i] = 0;
    cnt[i] = 0;
  }
  sort(magicvalue + 1, magicvalue + n + 1);
  for (int i = 1; i <= n; i++) {
    int val = magicvalue[i].first;
    int index = magicvalue[i].second;
    tot++;
    cnt[1]++;
    num[index] = 1;
    if (index < n && a[index] > a[index + 1]) merge(index, index + 1);
    if (index > 1 && a[index - 1] < a[index]) merge(index - 1, index);
    if (tot == cnt[num[findfather(index)]] && tot > maxnum) {
      ans = val + 1;
      maxnum = tot;
    }
  }
  cout << ans << endl;
}
