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;
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
void ASCII_Chart() {
  int i, j, k;
  printf("ASCII Chart:(30-129)\n");
  for (int i = 30; i < 50; i++) {
    for (int j = 0; j < 5; j++) {
      k = i + j * 20;
      printf("%3d---> '%c'   ", k, k);
    }
    printf("\n");
  }
}
double tick() {
  static clock_t oldt, newt = clock();
  double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
  oldt = newt;
  return diff;
}
const int INF = 0x3f3f3f3f;
float roundoff(float val, float p) {
  return floor(val * pow(10.0, p) + 0.5) / pow(10.0, p);
}
class node {
 public:
  int id;
  int prio;
  int prd;
};
class compare {
 public:
  bool operator()(node &n1, node &n2) {
    if (n1.prio > n2.prio)
      return true;
    else if (n1.prio == n2.prio) {
      return n1.id > n2.id;
    }
    return false;
  }
};
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  scanf("%d", &n);
  set<int> stt;
  map<int, int> mpp;
  vector<int> cntv(n + 1, 0);
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    set<int>::iterator it = stt.lower_bound(t);
    if (it == stt.end()) {
      cntv[t] = 0;
    } else {
      set<int>::iterator itt = it;
      if (++itt == stt.end()) {
        cntv[t] = *it;
        mpp[*it]++;
      } else {
        cntv[t] = -1;
      }
    }
    stt.insert(t);
  }
  set<int> st0, stg1, ste1, stl1;
  map<int, int> mpp2;
  for (int i = 1; i < n + 1; i++) {
    if (cntv[i] == 0) {
      st0.insert(i);
    } else if (cntv[i] == -1) {
      stl1.insert(i);
    } else {
      if (mpp[cntv[i]] > 1 && mpp2[cntv[i]] == 0) {
        stg1.insert(cntv[i]);
        mpp2[cntv[i]] = 1;
      } else {
        ste1.insert(cntv[i]);
      }
    }
  }
  if (stg1.size() > 0) {
    int maxm = -INF;
    int idx;
    for (set<int>::iterator it = stg1.begin(); it != stg1.end(); it++) {
      if (maxm < mpp[*it]) {
        maxm = mpp[*it];
        idx = *it;
      }
    }
    printf("%d", idx);
    goto x;
  } else {
    for (set<int>::iterator it = ste1.begin(); it != ste1.end(); it++) {
      if (cntv[*it] == -1) {
        printf("%d", *it);
        goto x;
      }
    }
    if (stl1.size() > 0) {
      printf("%d", *stl1.begin());
      goto x;
    } else {
      printf("%d", *st0.begin());
      goto x;
    }
  }
x:;
  return 0;
}
