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;
#pragma GCC optimize("Ofast")
void print(vector<long long> vvv) {
  for (auto it : vvv) cout << it << " ";
  cout << '\n';
}
long long mod = 1e9 + 7;
long long qpow(long long base, long long p) {
  if (p == 0) return 1;
  if (p == 1) return base % mod;
  long long r = qpow(base, p / 2);
  if (p % 2 == 0) return (r * r) % mod;
  return (((r * r) % mod) * base) % mod;
}
long long inv(long long a, long long b) {
  return (((a) % mod) * qpow(b, mod - 2)) % mod;
}
long long mand(pair<long long, long long> a, pair<long long, long long> b) {
  return abs(a.first - b.first) + abs(a.second - b.second);
}
vector<long long> v;
long long abi[200005];
long long cnt[200005];
void update(long long pos) {
  while (pos < 200005) {
    abi[pos]++;
    pos += (pos & -pos);
  }
}
long long query(long long pos) {
  long long ret = 0;
  while (pos > 0) {
    ret += abi[pos];
    pos -= (pos & -pos);
  }
  return ret;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    v.push_back(x);
  }
  long long ans = 0;
  long long pr = 1e16;
  deque<long long> q;
  for (long long i = 0; i < n; i++) {
    while (!q.empty() && v[q.back()] < v[i]) {
      q.pop_back();
    }
    long long men = query(v[i]);
    if (men == i) {
      cnt[i]++;
    }
    if (men == i - 1) {
      long long a = q.back();
      cnt[a]--;
    }
    q.push_back(i);
    update(v[i]);
  }
  long long mi = 1e18;
  for (long long i = 0; i < n; i++) {
    if (cnt[ans] >= cnt[i]) {
      if (cnt[ans] == cnt[i]) {
        if (v[i] < v[ans]) ans = i;
      } else {
        ans = i;
      }
    }
  }
  cout << v[ans] << '\n';
  return 0;
}
