#include <bits/stdc++.h>
using namespace std;
const int SIZ = 2e5 + 1007;
struct seg {
  int l, r;
  friend bool operator<(const seg &a, const seg &b) {
    if (a.l != b.l)
      return a.l < b.l;
    else
      return a.r < b.r;
  }
};
int N;
int A[SIZ], S[SIZ];
map<int, int> LUT;
int cnt = 0, ans = -1;
set<seg> cur;
int bucket[SIZ];
int check = 0;
int find_left(int pos) {
  seg q{pos, pos + 1};
  set<seg>::iterator i = cur.lower_bound(q);
  if (i == cur.begin()) return pos;
  --i;
  seg pre = *i;
  if (pre.r == pos) {
    cur.erase(i);
    int sel = pre.r - pre.l;
    bucket[sel]--;
    if (bucket[sel] == 0) check--;
    return pre.l;
  } else
    return pos;
}
int find_right(int pos) {
  seg q{pos, pos + 1};
  set<seg>::iterator i = cur.lower_bound(q);
  if (i == cur.end()) return pos + 1;
  seg pre = *i;
  if (pre.l == pos + 1) {
    cur.erase(i);
    int sel = pre.r - pre.l;
    bucket[sel]--;
    if (bucket[sel] == 0) check--;
    return pre.r;
  } else
    return pos + 1;
}
void upd(int k) {
  int pos = LUT[k];
  int l = find_left(pos);
  int r = find_right(pos);
  cur.insert(seg{l, r});
  bucket[r - l]++;
  if (bucket[r - l] == 1) check++;
  int ccnt = cur.size();
  if (check == 1 && cnt < ccnt) {
    cnt = ccnt, ans = k;
  }
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
    LUT[A[i]] = i;
    S[i] = A[i];
  }
  sort(S + 1, S + N + 1);
  for (int i = 1; i <= N; i++) upd(S[i]);
  printf("%d\n", ans + 1);
}
