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>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
const long long inf = 1ll << 60;
const long long iinf = 2147483647;
const long long mod = 1e9 + 7;
const long long maxn = 1e5 + 5;
long long pow(long long x, long long p) {
  long long ret = 1;
  while (p > 0) {
    if (p & 1) {
      ret *= x;
      ret %= mod;
    }
    x *= x;
    x %= mod;
    p >>= 1;
  }
  return ret;
}
long long inv(long long x) { return pow(x, mod - 2); }
bool cmp(long long x, long long y) { return x > y; }
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  long long n;
  cin >> n;
  vector<long long> vc(n), st(n), pf(n + 1), pfans(n + 1);
  pf[0] = 0;
  pfans[0] = 0;
  for (long long i = (0); i < (n); i++) {
    cin >> vc[i];
    pf[i + 1] = max(pf[i], vc[i]);
    if (i > 0) pfans[i] = pfans[i - 1];
    if (pf[i] < vc[i]) {
      pfans[i]++;
    }
  }
  pair<long long, long long> ans = {0, 1};
  for (long long i = n - 1; i >= 0; i--) {
    long long cur = lower_bound(st.begin(), st.end(), pf[i], cmp) - st.begin();
    if (i != 0) cur += pfans[i - 1];
    if (ans.first < cur) {
      ans.first = cur;
      ans.second = vc[i];
    } else if (ans.first == cur && ans.second > vc[i]) {
      ans.second = vc[i];
    }
    while (st.size() && st.back() < vc[i]) {
      st.pop_back();
    }
    st.push_back(vc[i]);
  }
  cout << ans.second << '\n';
}
