#include <bits/stdc++.h>
using namespace std;
void solve();
signed main() {
  srand(time(0));
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.precision(10);
  solve();
}
const long long MAXN = 2e5 + 10, INF = 1e18, MOD = 1e9 + 7;
long long n, CNT = 0;
long long a[MAXN], p[MAXN], cl[MAXN], sz[MAXN];
map<long long, long long> cnt;
long long get_set(long long first) {
  if (p[first] == first) {
    return first;
  }
  return p[first] = get_set(p[first]);
}
void union_set(long long a, long long b) {
  a = get_set(a);
  b = get_set(b);
  if (a != b) {
    cnt[sz[a]]--;
    cnt[sz[b]]--;
    sz[a] += sz[b];
    cnt[sz[a]]++;
    p[b] = a;
  }
}
void precalc() {
  for (long long i = 0; i < MAXN; ++i) {
    p[i] = i;
  }
}
void solve() {
  precalc();
  cin >> n;
  map<long long, long long> id;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    id[a[i]] = i;
  }
  long long ans = 0, k = INF;
  for (auto it : id) {
    long long num = it.first, i = it.second;
    sz[i] = 1;
    cnt[sz[i]]++;
    cl[i] = num;
    CNT++;
    if (i > 0 && cl[i - 1] != 0) {
      union_set(i, i - 1);
      CNT--;
    }
    if (i < n - 1 && cl[i + 1] != 0) {
      union_set(i, i + 1);
      CNT--;
    }
    long long pp = get_set(i);
    if (cnt[sz[pp]] == CNT) {
      if (ans < CNT) {
        ans = CNT;
        k = num;
      }
    }
  };
  cout << k + 1 << '\n';
}
