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;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
}
long long int fexp(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % 1000000007;
    b /= 2;
    a = a * a % 1000000007;
  }
  return ans;
}
long long int inverse(long long int a, long long int p) {
  return fexp(a, p - 2);
}
bool sortbysec(const pair<long long int, long long int> &a,
               const pair<long long int, long long int> &b) {
  if (a.second != b.second)
    return (a.second < b.second);
  else
    return a.first > b.first;
}
void ingraph(vector<vector<long long int> > &graph, long long int m) {
  long long int x, y;
  for (long long int i = 0; i < m; i++) {
    cin >> x >> y;
    x--, y--;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
}
long long int binsearch(vector<long long int> vec, long long int x) {
  long long int low = 0, high = vec.size() - 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  t = 1;
  while (t--) {
    long long int n;
    cin >> n;
    vector<long long int> arr(n);
    for (long long int i = 0; i < n; i++) cin >> arr[i];
    long long int mx, mn;
    vector<long long int> vec(n + 1), stat(n + 1);
    long long int tot = 0;
    if (arr.size() == 1)
      cout << arr[0];
    else if (arr.size() == 1)
      cout << min(arr[0], arr[1]);
    else {
      stat[arr[0]] = 1;
      tot = 1;
      mx = max(arr[0], arr[1]);
      mn = min(arr[0], arr[1]);
      if (arr[1] < arr[0])
        vec[arr[0]]++;
      else {
        stat[arr[1]] = 1;
        tot++;
      }
      for (long long int i = 2; i < n; i++) {
        if (arr[i] < mx) {
          if (arr[i] > mn) {
            vec[mx]++;
            mn = arr[i];
          }
        } else {
          tot++;
          stat[arr[i]]++;
          mn = mx;
          mx = arr[i];
        }
      }
      long long int temp = 1;
      for (long long int i = 1; i < n + 1; i++) {
        if (vec[i] - stat[i] > vec[temp] - stat[temp]) temp = i;
      }
      cout << temp << endl;
    }
  }
}
