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.
//Standard template for my java code: Arun Ganesh//
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {
    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;
 
        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
 
        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
 
        public String readLine() throws IOException
        {
            byte[] buf = new byte[1000001]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }
 
        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');
 
            if (neg)
                return -ret;
            return ret;
        }
 
        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }
 
        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
 
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
 
            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }
 
            if (neg)
                return -ret;
            return ret;
        }
 
        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }
 
        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }
 
        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
   static StringBuilder fin = new StringBuilder("");
   static long mod = 1000000007;
   
    public static void main(String[] args) throws IOException {
		Reader in = new Reader();
		int n = in.nextInt();
		int a[]= new int[n];
		ArrayList<Integer> b = new ArrayList<Integer>();
		ArrayList<Integer> al = new ArrayList<Integer>();
		ArrayList<Integer> mis= new ArrayList<Integer>();
		int ans = -1,ma=0,minas= 1000000;
		for(int i=0;i<n;++i)
		{
			a[i] = in.nextInt();
			if(a[i] >ma)
			{
				ma = a[i];
				b.add(a[i]);
				continue;
			}
			mis.add(a[i]);
		}

		int ind = 0,ge,tcount =-1,prge=1000000;
		ge = b.get(ind);
		for(int i =0;i<n;++i)
		{
			if(ge == a[i])
			{
				
				if(tcount > ans)
				{
					ans = tcount;
					minas = prge;
				}
				if(tcount == ans)
				{
					minas = Math.min(minas,prge);
				}
				prge = ge;
				ind++;
				if(ind < b.size())
					ge = b.get(ind);
				al.add(prge);
				tcount =-1;
				continue;
			}
			int where = Collections.binarySearch(al,a[i]);
			where = Math.abs(where + 1);
			//System.out.println(a[i] + " " + where);
			if(where == al.size()-1)
				tcount++;
			al.add(where,a[i]);
		}
		//System.out.println(tcount);
		prge = ge;
		if(tcount > ans)
				{
					ans = tcount;
					minas = prge;
				}
				if(tcount == ans)
				{
					minas = Math.min(minas,prge);
				}
		if(ans <=0)
		{
			if(mis.size()>0)
			{
			Collections.sort(mis);
			
			minas = mis.get(0);
			}
		}
		fin.append(minas);
		System.out.print(fin);
		
	}

 static long modInverse(long a, long m)
{
    
    
        
       return power(a, m-2, m);
    
}
 
// To compute x^y under modulo m
static long power(long x, long y, long m)
{
    if (y == 0)
        return (long)1;
    long p = power(x, y/2, m) % m;
    p = (p * p) % m;
 
    return (y%2 == 0)? p : (x * p) % m;
}
/*static class dj{
	int par[],n,rank[];
	List<ArrayList<Integer>> al = new ArrayList<ArrayList<Integer>>();
	dj(int n)
	{
		this.n=n;
		par = new int[n+5];
		rank = new int[n+5];
		for(int i=0;i<=n;++i)
			par[i] = i;
	}
	public void mp(int x,int y)
	{
		int par1 = find(x);
		int par2 = find(y);
		if(rank[par1] >rank[par2])
		{
		par[par2] = par1;
		rank[par1]++;
		}
		else
		{
			par[par1] = par2;
			rank[par2]++;
		}
	}
	public int find(int x)
	{
		while(x!=par[x])
		{
			x = par[x];
		}
		return x;
	}
	public long finish()
	{
		for(int i=0;i<2005;++i)
			al.add(new ArrayList<Integer>());
		for(int i=0;i<n;++i)
			par[i] = find(i);
		for(int i=0;i<n;++i) System.out.print(par[i]+ " ");System.out.println();
		int ans[] = new int[2005];
		int cnt[] = new int[2005];
		for(int i=0;i<n;++i)
			for(int j=0;j<n;++j)
				cnt[i] = cnt[i]+a[i][j];
		Arrays.fill(ans,-1);
		int ind=0;
		for(int i=0;i<n;++i)
		{
			int temp = par[i];
			if(ans[temp] == -1)
			{
				ans[temp] = ind;
				ind++;
				
			}
			al.get(ans[temp]).add(i);
		}
		long sum=0;
		for(int i=0;i<n;++i){
			for(int j=0;j<al.get(i).size();++j)
			{
				System.out.print(al.get(i).get(j) + " ");
			    sum = sum + (al.get(i).size() - cnt[al.get(i).get(j)] -1);
			}
			System.out.println();
	}
					

		
		return sum;
	}
}*/
 

 

  }
 
