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

public final class round_450_a
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static int[] bit;
	static int n;
	
	static void update(int idx,int val)
	{
		while(idx>0)
		{
			bit[idx]+=val;idx-=idx&-idx;
		}
	}
	
	static int query(int idx)
	{
		int ret=0;
		
		while(idx<=n)
		{
			ret=ret+bit[idx];idx+=idx&-idx;
		}
		
		return ret;
	}
	
    public static void main(String args[]) throws Exception
    {
		n=sc.nextInt();int[] a=new int[n+1];bit=new int[n+1];
		
		int[] pos=new int[n+1];
		
		for(int i=1;i<=n;i++)
		{
			a[i]=sc.nextInt();pos[a[i]]=i;
		}
		
		int[] val=new int[n+1];int max=0;
		
		for(int i=1;i<=n;i++)
		{
			int now=query(a[i]);
			
			if(now==1)
			{
				val[pos[max]]++;
			}
			
			max=Math.max(max,a[i]);update(a[i],1);
		}
		
		int[] val2=new int[n+1],add=new int[n+1];max=0;
		
		for(int i=1;i<=n;i++)
		{
			max=Math.max(max,a[i]);
			
			if(a[i]==max)
			{
				add[i]=1;
			}
		}
		
		int get=0;
		
		for(int i=n;i>=1;i--)
		{
			val2[i]=get;
			
			get+=add[i];
		}
		
	//	out.println(Arrays.toString(val)+" "+Arrays.toString(val2));
		
		int curr=0,z=-1,res=Integer.MAX_VALUE;max=0;
		
		for(int i=1;i<=n;i++)
		{
			int now=curr+val[i]+val2[i];
			
			if(now>z)
			{
				z=now;res=a[i];
			}
			
			else if(now==z)
			{
				res=Math.min(res,a[i]);
			}
			
			if(a[i]>max)
			{
				curr++;max=a[i];
			}
		}
		
		out.println(res);out.close();
    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }
	
    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
	
	public String next() throws Exception {
		return nextToken().toString();
	}
	
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}