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.
/**
 * @author Finn Lidbetter
 */
import java.util.*;
import java.io.*;
import java.awt.geom.*;

public class TaskC {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();
    
    int n = Integer.parseInt(br.readLine());
    String[] s = br.readLine().split(" ");
    int[] arr = new int[n];
    ArrayList<Integer> incList = new ArrayList<>();
    int[] valToIncIndex = new int[n+1];
    int[] incIndexToValIndex = new int[n];
    Arrays.fill(valToIncIndex,-1);
    int prev = 0;
    int index = 0;
    for (int i=0; i<n; i++) {
      arr[i] = Integer.parseInt(s[i]);
      if (arr[i]>prev) {
        incList.add(arr[i]);
        prev = arr[i];
        valToIncIndex[arr[i]] = index;
        incIndexToValIndex[index] = i;
        index++;
      }
    }
    int[] inc = new int[index];
    for (int i=0; i<index; i++) {
      inc[i] = incList.get(i);
    }
    int[] nRecs = new int[n];
    int[] max = new int[n];
    int cMax = 0;
    int cRecs = 0;
    for (int i=0; i<n; i++) {
      if (arr[i]>cMax) {
        cRecs++;
        cMax = arr[i];
      }
      nRecs[i] = cRecs;
      max[i] = cMax;
    }
    int best = 0;
    int bestVal = Integer.MAX_VALUE;
    for (int i=0; i<n; i++) {
      int v = arr[i];
      if (valToIncIndex[v]==-1) {
        continue;
      }
      int incIndex = valToIncIndex[v];
      int nValIndex = (incIndex>=inc.length-1) ?  n : incIndexToValIndex[incIndex+1];
      int pMax = (i==0) ? 0 : max[i-1];
      int count = 0;
      for (int j=i+1; j<nValIndex; j++) {
        if (arr[j]>pMax) {
          pMax = arr[j];
          count++;
        }
      }
      //System.out.printf("v: %d, nValIndex: %d, count: %d\n",v,nValIndex, count);
      if (count>=best) {
        if (count>best) {
          best = count;
          bestVal = arr[i];
        } else if (count==best && arr[i]<bestVal) {
          bestVal = arr[i];
        }
      }
    }
    int min = bestVal;
    if (best==1) {
      min = bestVal;
      for (int i=0; i<n; i++) {
        if (arr[i]!=max[i] && arr[i]<min) {
          min = arr[i];
        }
      }
    } else if (best==0) {
      min = n;
      for (int i=0; i<n; i++) {
        if (arr[i]!=max[i] && arr[i]<min) {
          min = arr[i];
        }
      }
    }
    boolean allRecs = true;
    for (int i=0; i<n; i++) {
      if (arr[i]!=max[i]) {
        allRecs = false;
        break;
      }
    }
    if (allRecs) {
      min = 1;
    }
    System.out.println(min);
  }
}
