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>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long double pii = 3.14159265359;
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001;
class FenwickTree {
  vector<int> ft;

 public:
  FenwickTree(int n) { ft.assign(n + 1, 0); }
  long long rsq(int b) {
    long long sum = 0;
    while (b > 0) {
      sum += ft[b];
      b -= b & (-b);
    }
    return sum;
  }
  long long rsq(int a, int b) { return rsq(b) - (a == 1 ? 0 : rsq(a - 1)); }
  void add(int k, long long v) {
    while (k < ft.size()) {
      ft[k] += v;
      k += k & (-k);
    }
  }
  int find(int k) {
    int l = 1, r = ft.size() - 1;
    int pos = 0;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (rsq(mid) >= k) {
        pos = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    return pos;
  }
};
void solve() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (auto& i : v) cin >> i;
  vector<int> r(N), l(N);
  FenwickTree f1(MX), f2(MX);
  f1.add(v[0], 1);
  set<int> S;
  S.insert(v[0]);
  map<int, int> m;
  vector<bool> rec(MX);
  pair<int, int> ans = {-1, v[0]};
  rec[v[0]] = 1;
  for (int x = 1; x < (N); x++) {
    int val = f1.rsq(v[x]);
    if (val == x - 1) {
      int g = (*S.upper_bound(v[x]));
      m[g]++;
    }
    if (val == x) rec[v[x]] = 1;
    f1.add(v[x], 1);
    S.insert(v[x]);
  }
  for (int x = 0; x < (N); x++) {
    cerr << (m[v[x]] - rec[v[x]]) << nl;
    if (ckmax(ans.first, m[v[x]] - rec[v[x]]))
      ans.second = v[x];
    else if (ans.first == m[v[x]] - rec[v[x]])
      ckmin(ans.second, v[x]);
  }
  cout << ans.second;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int Test_case = 1;
  while (Test_case-- != 0) {
    solve();
  }
  return 0;
}
