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 double PI = 3.14159265358979323846;
long long int N_Sieve = 1e4;
vector<bool> sieve_primes(N_Sieve, true);
vector<long long int> primes;
void sieve() {
  for (long long int i = 2; i < N_Sieve; i++) {
    if (sieve_primes[i]) {
      primes.push_back(i);
      for (long long int j = i * i; j < N_Sieve; j += i) {
        sieve_primes[j] = false;
      }
    }
  }
}
long long int nC2(long long int num) {
  int num1 = num - 1;
  if (num % 2)
    num1 /= 2;
  else
    num /= 2;
  num *= num1;
  return num;
}
long long int fact(long long int num, long long int mod) {
  long long int ans = 1;
  for (int i = 2; i <= num; i++) {
    ans *= i;
    ans = ans % mod;
  }
  return ans;
}
long long int sigma(long long int num) {
  long long int num1 = num + 1;
  if (num & 1)
    num1 /= 2;
  else
    num /= 2;
  return num1 * num;
}
int div_sq(int num) {
  int ans = 1;
  for (int i = 0; i < N_Sieve && primes[i] * primes[i] <= num; i++) {
    int cnt = 0;
    while (num % primes[i] == 0) {
      num /= primes[i];
      cnt++;
    }
    if (cnt % 2) ans *= primes[i];
  }
  if (num > 1) ans *= num;
  return ans;
}
struct item {
  int mini, maxi, end;
};
struct segment_tree {
  vector<item> vec;
  int size;
  item DEFAULT = {0, 0, 0};
  void init(int n) {
    size = 1;
    while (size < n) size *= 2;
    vec.assign(2 * size, DEFAULT);
  }
  void print() {
    for (int i = 0; i < 2 * size; i++)
      cout << i << ":" << vec[i].mini << ' ' << vec[i].maxi << ' ' << vec[i].end
           << endl;
    cout << endl;
  }
  item single(int val) { return {val, val, val}; }
  item merge(item a, item b) {
    return {min(0, min(a.mini, a.end + b.mini)),
            max(0, max(a.maxi, a.end + b.maxi)), a.end + b.end};
  }
  void set(int i, int val, int x, int lx, int rx) {
    if (rx - lx == 1) {
      vec[x] = single(val);
      return;
    }
    int m = (lx + rx) / 2;
    if (i < m)
      set(i, val, 2 * x + 1, lx, m);
    else
      set(i, val, 2 * x + 2, m, rx);
    vec[x] = merge(vec[2 * x + 1], vec[2 * x + 2]);
  }
  void set(int i, int val) { set(i, val, 0, 0, size); }
  item get_res(int l, int r, int x, int lx, int rx) {
    if (l >= rx || r <= lx) return vec[x];
    if (lx >= l && rx <= r) return DEFAULT;
    int m = (lx + rx) / 2;
    return merge(get_res(l, r, 2 * x + 1, lx, m),
                 get_res(l, r, 2 * x + 2, m, rx));
  }
  item get_res(int l, int r) { return get_res(l, r, 0, 0, size); }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int maxi = 0, initial = 0;
  vector<int> khud_hai(n + 1, 0);
  set<int> S;
  map<int, int> dict;
  for (int i = 1; i <= n; i++) dict[i] = 0;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    auto it = S.lower_bound(num);
    if (it == S.end()) {
      initial++;
      khud_hai[num] = 1;
    } else {
      if (*it == maxi) dict[*it]++;
    }
    maxi = max(maxi, num);
    S.insert(num);
  }
  int max_at = INT_MAX;
  maxi = 0;
  for (auto it = dict.begin(); it != dict.end(); it++) {
    if (initial + it->second - khud_hai[it->first] > maxi) {
      maxi = initial + it->second - khud_hai[it->first];
      max_at = it->first;
    } else if (initial + it->second - khud_hai[it->first] == maxi)
      max_at = min(max_at, it->first);
  }
  if (max_at == INT_MAX)
    cout << 1;
  else
    cout << max_at;
  return 0;
}
