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.
import java.io.*;
import java.math.*;
import java.util.*;

public class Main{
    public static int num(int r,int i,int e,int[] a){
        int k = 0;
        int max=r;
        for(int j=i+1;j<e;j++){
            //System.out.println(a[i]+" "+max+" "+k);
            if(a[j]>max){
                max = a[j];
                k++;
            }
        }
        return k;
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        if(n==1){
            n = Integer.parseInt(br.readLine());
            System.out.println("1");
        }else{
            StringTokenizer st = new StringTokenizer(br.readLine());
            LinkedList<Integer> al = new LinkedList<Integer>();
            al.add(0);
            int[] a = new int[n];
            for(int i=0;i<n;i++){
                a[i] = Integer.parseInt(st.nextToken());
            }
            int max = a[0];
            for(int i=0;i<n;i++){
                if(a[i]>max) {
                    max  = a[i];
                    al.add(i);
                }
            }
            if(al.size()==1) {
                //System.out.println(num(0,0,n,a));
                if(num(0,0,n,a)>1) System.out.println(a[al.get(0)]);
                else{
                    System.out.println("1");
                }
            }
            else{
                int[][] c =new int[al.size()][2];
                int[] b =new int[al.size()+1];
                int l =0;
                for(int x:al){
                    b[l] = x;
                    c[l][0] = a[x];
                    l++;
                }
                b[l] = n;
                int rec = 0,nrec = 0;
                for(int i=0;i<l;i++){
                    c[i][1] = num(rec,b[i],b[i+1],a);
                    rec = a[b[i]];
                }
                int min = c[0][0];
                int vm = c[0][1];
                for(int i=1;i<l;i++){
                    if(vm<c[i][1]){
                        min = c[i][0];
                        vm = c[i][1];
                    }else if(vm==c[i][1]){
                        if(min>c[i][0]) min = c[i][0];
                    }
                }
                //System.out.println(vm+" "+min);
                if(vm<=1){
                    TreeSet<Integer> hs = new TreeSet<Integer>();
                    for(int i=1;i<n;i++) hs.add(i);
                    for(int i=0;i<l;i++) if(hs.contains(c[i][0])) hs.remove(c[i][0]);
                    if(hs.size()==0) System.out.println(min); 
                    else if(vm==1) System.out.println(Math.min(hs.first(),min));
                    else System.out.println(hs.first());
                }
                else System.out.println(min);
            }
        }
        
    }
}












