You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible.

We remind that in a sequence of numbers a1, a2, ..., ak the element ai is a record if for every integer j (1 ≤ j < i) the following holds: aj < ai. 

Input

The first line contains the only integer n (1 ≤ n ≤ 105) — the length of the permutation.

The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation. All the integers are distinct.

Output

Print the only integer — the element that should be removed to make the number of records the maximum possible. If there are multiple such elements, print the smallest one.

Examples

Input

1
1


Output

1


Input

5
5 1 2 3 4


Output

5

Note

In the first example the only element can be removed.
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename S>
using P = pair<T, S>;
template <class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;
using LD = long double;
template <typename T, typename S>
void check(T &a, S &b) {
  if (a >= b) {
    a %= b;
  }
}
template <typename T>
T gcd(T u, T v) {
  if (u == v) return u;
  if (u == 0) return v;
  if (v == 0) return u;
  if (~u & 1) {
    if (v & 1)
      return gcd(u >> 1, v);
    else
      return gcd(u >> 1, v >> 1) << 1;
  }
  if (~v & 1) return gcd(u, v >> 1);
  if (u > v) return gcd((u - v) >> 1, v);
  return gcd((v - u) >> 1, u);
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') {
    cerr << *sdbg++;
  }
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, a...);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  if (0) cout.tie(NULL);
  ;
  int n;
  cin >> n;
  V<int> v(n + 1);
  for (int i = 1; i <= (int)n; i++) cin >> v[i];
  V<int> M(n + 1, 0);
  int _ans = 0;
  V<int> ch(n + 1, 0);
  for (int i = 1; i <= (int)n; i++) {
    if (M[i - 1] < v[i]) {
      ch[i] = 1;
      _ans++;
    }
    M[i] = (!i ? v[i] : max(v[i], M[i - 1]));
  }
  V<int> ans(n + 1, 0);
  V<int> pre(n + 1, 0);
  stack<int> S;
  for (int i = 1; i <= n; i++) {
    while (!S.empty() && v[S.top()] < v[i]) {
      S.pop();
    }
    if (!S.empty()) {
      pre[i] = S.top();
    }
    S.push(i);
  }
  for (int i = 2; i <= n; i++) {
    if (pre[i] && M[pre[i] - 1] < v[i]) {
      ans[pre[i]]++;
    }
  }
  int first = _ans + ans[1] - ch[1];
  int num = v[1];
  for (int i = 2; i <= n; i++) {
    if (first < _ans + ans[i] - ch[i]) {
      first = _ans + ans[i] - ch[i];
      num = v[i];
    } else if (first == _ans + ans[i] - ch[i]) {
      num = min(num, v[i]);
    }
  }
  cout << num << '\n';
  if (0)
    cout << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms"
         << '\n';
  return 0;
}
