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>
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int bmod(int a, int b, int m) {
  if (b == 0) return 1;
  int x = bmod(a, b / 2, m);
  x = (x * x) % m;
  if (b % 2 == 1) x = (x * a) % m;
  return x;
}
long long powr(long long n, long long m) {
  long long ans = 1;
  for (long long i = 1; i <= m; i++) ans *= n;
  return ans;
}
bool prime(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
int Setbit(long long N, long long pos) { return N = N | (1 << pos); }
int resetbit(long long N, long long pos) { return N = N & ~(1 << pos); }
bool checkbit(long long N, long long pos) { return (bool)(N & (1 << pos)); }
void countDivisor(long long num) {
  for (long long i = 1; i * i <= num; i++) {
    if (num % i == 0) {
    }
  }
}
long long fx[8] = {0, +0, -1, +1, +1, -1, -1, +1};
long long fy[8] = {1, -1, +0, +0, +1, +1, -1, -1};
using namespace std;
long long fst[100005 + 5], scn[100005 + 5], arr[100005 + 5], pos[100005 + 5],
    trk[100005 + 5], ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> arr[i];
    trk[arr[i]] = i;
    fst[i] = arr[i];
    scn[i] = arr[i];
  }
  scn[1] = 0;
  for (long long i = 2; i <= n; i++) {
    fst[i] = max(fst[i], fst[i - 1]);
    if (fst[i] == arr[i]) {
      scn[i] = fst[i - 1];
    } else {
      scn[i] = max(arr[i], scn[i - 1]);
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (arr[i] != fst[i]) {
      if (arr[i] == scn[i]) {
        pos[fst[i]]++;
      } else if (arr[i] < ans || ans == 0)
        ans = arr[i];
    }
  }
  long long tmp = 0, flag = 0;
  for (long long i = 1; i <= n; i++) {
    if (i == arr[1] && pos[i] == 1) continue;
    if (pos[i] > tmp && pos[i] > 1) {
      ans = i;
      tmp = pos[i];
    }
  }
  ans = max(1LL, ans);
  cout << ans << endl;
}
