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;
int tree[4 * 100005];
int arr[100005];
void build(int node, int st, int en) {
  if (st == en) {
    tree[node] = arr[st];
    return;
  }
  int mid = (st + en) / 2;
  build(2 * node, st, mid);
  build(2 * node + 1, mid + 1, en);
  tree[node] = tree[2 * node] + tree[2 * node + 1];
}
int query(int node, int l, int r, int st, int en) {
  if (l > r) return 0;
  if (r < st || l > en) return 0;
  if (st >= l && en <= r) return tree[node];
  int mid = (st + en) / 2;
  int a = query(2 * node, l, r, st, mid);
  int b = query(2 * node + 1, l, r, mid + 1, en);
  return (a + b);
}
void update(int node, int ind, int st, int en, int val) {
  if (ind < st || ind > en) return;
  if (st == en) {
    arr[ind] += val;
    tree[node] += val;
    return;
  }
  int mid = (st + en) / 2;
  update(2 * node, ind, st, mid, val);
  update(2 * node + 1, ind, mid + 1, en, val);
  tree[node] = tree[2 * node] + tree[2 * node + 1];
}
int a[100005];
int b[100005];
int c[100005];
set<pair<int, int> > st;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (n == 1) {
    cout << a[0] << endl;
    return 0;
  }
  int ans = INT_MAX;
  pair<int, int> tmp;
  for (int i = 0; i < n; ++i) {
    int x = query(1, 1, a[i] - 1, 1, n);
    if (x == i - 1) {
      tmp = *st.upper_bound(make_pair(a[i] + 1, n - i));
      b[n - tmp.second]++;
    } else if (x == i)
      c[i] = 1;
    st.insert(make_pair(a[i], n - i));
    update(1, a[i], 1, n, 1);
  }
  int mx = -1;
  for (int i = 0; i < n; i++) {
    if (b[i] - c[i] > mx) {
      mx = b[i] - c[i];
      ans = a[i];
    }
    if (b[i] - c[i] == mx) {
      ans = min(a[i], ans);
    }
  }
  cout << ans << endl;
}
