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 n;
int a[110000];
int m[110000][25];
int p[25];
int l[110000];
int c[110000];
int init_RMQ() {
  int i, k, len;
  for (i = 1; i <= n; i++) m[i][0] = i;
  len = 1;
  for (k = 1; k <= 20; k++) {
    for (i = 1; i <= n - 2 * len + 1; i++) {
      m[i][k] = m[i][k - 1];
      if (a[m[i + len][k - 1]] > a[m[i][k - 1]]) m[i][k] = m[i + len][k - 1];
    }
    len = len * 2;
  }
  return 0;
}
int init_L() {
  int i;
  for (i = 1; i <= n; i++) {
    l[i] = i - 1;
    while (a[l[i]] < a[i]) l[i] = l[l[i]];
  }
  return 0;
}
int find_max(int i, int u) {
  int k, len, x, y;
  if (u == 1) return i;
  k = 0;
  len = 1;
  while (2 * len <= u) {
    k++;
    len = 2 * len;
  }
  x = m[i][k];
  if (u > len) {
    y = find_max(i + len, u - len);
    if (a[y] > a[x]) x = y;
  }
  return x;
}
int solve() {
  int i, k, u, v, res;
  for (i = 1; i <= n; i++)
    if (l[i] != 0) {
      k = l[i];
      if (k > 1)
        u = find_max(1, k - 1);
      else
        u = find_max(k + 1, i - k);
      v = find_max(k + 1, i - k);
      if (a[v] > a[u]) u = v;
      if (a[u] <= a[i]) c[l[i]]++;
    } else
      c[i]--;
  res = 1;
  for (i = 2; i <= n; i++) {
    if (c[i] > c[res])
      res = i;
    else if ((c[i] == c[res]) && (a[i] < a[res]))
      res = i;
  }
  cout << a[res];
  return 0;
}
int main() {
  int i;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  a[0] = 1000000;
  init_RMQ();
  init_L();
  solve();
  return 0;
}
