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 siev[1000005];
void sieve() {
  for (int i = 2; i <= 1e6; i++) {
    if (siev[i] == 0) {
      for (int j = i; j <= 1e5; j += i) siev[j] = i;
    }
  }
}
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  while (b != 0) {
    long long temp = b;
    b = a % b;
    a = temp;
  }
  return a;
}
int power(int x, int y) {
  if (y == 0) return 1;
  int p = power(x, y / 2);
  p = (p * p);
  return (y % 2 == 0) ? p : (x * p);
}
int gcdExtended(int a, int b, int *x, int *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
void modInverse(int a, int m) {
  int x, y;
  int g = gcdExtended(a, m, &x, &y);
  int res = (x % m + m) % m;
}
const int N = 100005;
int a[N], b[N], tree[60 * N];
void update(int s, int e, int l, int node, int val) {
  if (s == e) {
    tree[node] += val;
    return;
  }
  int mid = (s + e) / 2;
  if (l <= mid)
    update(s, mid, l, 2 * node + 1, val);
  else
    update(mid + 1, e, l, 2 * node + 2, val);
  tree[node] = tree[2 * node + 1] + tree[2 * node + 2];
}
long long query(int s, int e, int l, int r, int node) {
  if (s > e || e < l || s > r) return 0;
  if (s >= l && e <= r) return tree[node];
  int mid = (s + e) / 2;
  long long x = query(s, mid, l, r, 2 * node + 1);
  long long y = query(mid + 1, e, l, r, 2 * node + 2);
  return (x + y);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int u = query(0, N, a[i] + 1, N, 0);
    if (u == 0)
      b[i] = -1;
    else if (u == 1)
      b[i] = 1;
    else
      b[i] = 0;
    update(0, N, a[i], 0, 1);
  }
  int i = 0, cnt = 0, ans = 0, pos = 0, last = 0;
  for (; i < n; i++) {
    if (b[i] == -1) {
      last = i;
      i++;
      break;
    }
  }
  for (; i < n; i++) {
    if (b[i] == -1) {
      if (ans < cnt - 1) {
        pos = last;
        ans = cnt - 1;
      }
      cnt = 0;
      last = i;
    } else
      cnt += b[i];
  }
  if (ans < cnt - 1) {
    pos = last;
    ans = cnt - 1;
  }
  if (ans == 0) {
    int x = a[0], fl = 1;
    for (int i = 0; i < n; i++) {
      if (b[i] != -1 && fl == 1) x = a[i], fl = 0;
      if (b[i] != -1 && x > a[i]) x = a[i];
    }
    cout << x << "\n";
  } else
    cout << a[pos] << "\n";
  return 0;
}
