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 optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
const long long MOD = 1e+9 + 7;
const long long INF = LLONG_MAX;
const int INFi = INT_MAX;
const long long N = 2e+5 + 8;
vector<long long> adj[N];
long long vis[N];
long long dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};
long long test_cases = 1;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
;
long long n, a[N], mx1[N], mx2[N], flag[N], first[N], ID[N],
    total = 0, ans = -INF, val = INF;
void MAIN(long long tc) {
  cin >> n;
  for (long long i = (1); i <= n; i++) cin >> a[i];
  ;
  for (long long i = (1); i <= n; i++) ID[a[i]] = i, first[i] = 0;
  mx1[1] = a[1];
  mx2[1] = 0;
  mx1[2] = max(a[1], a[2]);
  mx2[2] = min(a[1], a[2]);
  for (long long i = (2); i <= n; i++) mx1[i] = max(mx1[i - 1], a[i]);
  for (long long i = (3); i <= n; i++) {
    if (a[i] == mx1[i])
      mx2[i] = mx1[i - 1];
    else
      mx2[i] = max(mx2[i - 1], a[i]);
  }
  for (long long i = (1); i <= n; i++) {
    if (a[i] < mx1[i - 1] && mx2[i - 1] < a[i]) {
      first[ID[mx1[i - 1]]]++;
    } else if (a[i] >= mx1[i]) {
      total++;
      flag[i] = 1;
    }
  }
  for (long long i = (1); i <= n; i++)
    ans = max(ans, total - flag[i] + first[i]);
  for (long long i = (1); i <= n; i++) {
    if (ans == total - flag[i] + first[i]) {
      val = min(val, a[i]);
    }
  }
  cout << val;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(10);
  ;
  for (long long i = (1); i <= test_cases; i++) {
    MAIN(i);
  }
}
