#include <bits/stdc++.h>
using namespace std;
long long arr[100010], ans, Par[100010], piles_with_number[100010],
    sizearr[100010], num_piles = 0, best_num_piles = 0;
vector<pair<long long, long long> > V;
long long find_P(int pos) {
  if (Par[pos] == pos) return pos;
  return Par[pos] = find_P(Par[pos]);
}
void unionfunc(int x, int y) {
  int Px = find_P(x), Py = find_P(y);
  piles_with_number[sizearr[Px]]--;
  piles_with_number[sizearr[Py]]--;
  sizearr[Py] += sizearr[Px];
  Par[Px] = Py;
  piles_with_number[sizearr[Py]]++;
  num_piles--;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, i;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    V.push_back(make_pair(arr[i], i + 1));
  }
  sort(V.begin(), V.end());
  for (i = 0; i < n; i++) {
    long long ind = V[i].second - 1, val = V[i].first;
    num_piles++;
    Par[ind] = ind;
    sizearr[ind] = 1;
    piles_with_number[sizearr[ind]]++;
    if (ind > 0 && arr[ind - 1] < val) {
      fprintf(stderr, "1done\n");
      unionfunc(ind - 1, ind);
    }
    if (ind < n - 1 && arr[ind + 1] < val) {
      fprintf(stderr, "2done\n");
      unionfunc(ind + 1, ind);
    }
    fprintf(stderr, "%lld %lld %lld ", num_piles, sizearr[ind],
            piles_with_number[sizearr[ind]]);
    if (num_piles == piles_with_number[sizearr[ind]] &&
        num_piles > best_num_piles) {
      ans = val;
      best_num_piles = num_piles;
    }
    fprintf(stderr, "%lld\n\n", ans);
  }
  cout << ans + 1 << endl;
  return 0;
}
