#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-3;
const int MAXN = 1e5 + 10;
const int MAXM = 1e4 + 10;
const long long mod = 1e9;
int a[MAXN], l[MAXN], r[MAXN];
bool vis[MAXN];
map<int, int> mp;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    mp[a[i]] = i;
  }
  sort(a + 1, a + 1 + n);
  int ans = a[n] + 1, cnt = 0, len = 0, sum = 1;
  for (int i = 1; i <= n; i++) {
    int pos = mp[a[i]];
    vis[pos] = true;
    if (vis[pos - 1] && vis[pos + 1]) {
      l[pos] = l[pos - 1];
      r[pos] = r[pos + 1];
      l[r[pos + 1]] = l[pos - 1];
      r[l[pos - 1]] = r[pos + 1];
    } else if (vis[pos - 1]) {
      l[pos] = l[pos - 1];
      r[pos] = pos;
      r[l[pos - 1]] = pos;
    } else if (vis[pos + 1]) {
      l[pos] = pos;
      r[pos] = r[pos + 1];
      l[r[pos + 1]] = pos;
    } else {
      cnt++;
      l[pos] = pos;
      r[pos] = pos;
    }
    len = max(len, r[pos] - l[pos] + 1);
    if (len * cnt == i) {
      if (cnt > sum) {
        sum = cnt;
        ans = a[i] + 1;
      } else if (cnt == sum && a[i] + 1 < ans)
        ans = a[i] + 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}
