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;
void merge(vector<int> &dest, vector<int> &a, vector<int> &b) {
  dest.clear();
  if (a[0] != 0)
    for (int i = 0; i < a.size(); i++) dest.push_back(a[i]);
  for (int i = 0; i < b.size(); i++) {
    if (!dest.size() || (dest.size() && dest.back() < b[i]))
      dest.push_back(b[i]);
  }
}
void build(vector<vector<int>> &tree, vector<int> &data, int v, int l, int r) {
  if (l == r) {
    tree[v].push_back(data[l]);
    return;
  }
  int mid = l + (r - l) / 2;
  build(tree, data, 2 * v, l, mid);
  build(tree, data, 2 * v + 1, mid + 1, r);
  merge(tree[v], tree[2 * v], tree[2 * v + 1]);
}
void update(vector<vector<int>> &tree, int val, int idx, int v, int l, int r) {
  if (idx < l || r < idx) return;
  if (l == r) {
    if (l == idx) {
      tree[v][0] = val;
    }
    return;
  }
  int mid = l + (r - l) / 2;
  update(tree, val, idx, 2 * v, l, mid);
  update(tree, val, idx, 2 * v + 1, mid + 1, r);
  merge(tree[v], tree[2 * v], tree[2 * v + 1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  ;
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<vector<int>> tree(4 * n);
  build(tree, a, 1, 0, n - 1);
  int max_v = -1, ans = n + 1;
  for (int i = 0; i < n; i++) {
    int t = a[i];
    update(tree, 0, i, 1, 0, n - 1);
    if ((int)tree[1].size() >= max_v) {
      if ((int)tree[1].size() == max_v)
        ans = min(ans, a[i]);
      else
        ans = a[i];
      max_v = tree[1].size();
    }
    update(tree, t, i, 1, 0, n - 1);
  }
  cout << ans << endl;
  return 0;
}
