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.*;

public class Practice {

	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;
    public static void main(String[] args) {
    	InputReader(System.in);
		pw = new PrintWriter(System.out); 
        new Thread(null ,new Runnable(){
           public void run(){
               try{
                   solve();//This is solution method
           pw.close();
       } catch(Exception e){
           e.printStackTrace();
       }
   }
},"1",1<<26).start();
        }
    
    static int st[];
    private static void solve(){
    
    	 int t=1;
         while(t-->0)
         {
             int n=nextInt();
             
             int a[]=nextIntArray(n);
             st=new int[400005];
             
             int inversions=0;
             int small_left[]=new int[n];
             int big_left[]=new int[n];
             int tot_rec=0;
             for(int i=0;i<n;i++)
            	 
             {
                 int Small_in_left=query(1,1,100000,a[i]+1,100000);
                 small_left[i]=Small_in_left;
                 if(small_left[i]==0){
                	 tot_rec++;
                 }
                 
                 update(1,1,100000,a[i],1);
             }
             
             Arrays.fill(st, 0);
             int temp=0;
             int ans=Integer.MIN_VALUE;
             int nu=Integer.MAX_VALUE;
             for(int i=n-1;i>=0;i--){
            	 int small_right = query(1, 1, 100000, 1, a[i]-1);
            	temp=small_right;
            	 temp+=tot_rec;
            	if(small_left[i]==0){
            		temp--;
            	}
            	if(ans==temp){
            		nu=Math.min(nu, a[i]);
            	}
            	else if(ans<temp){
            		ans=temp;
            		nu=a[i];
            	}
            	if(small_left[i]==1){
            		update(1, 1, 100000, a[i], 1);
            	}
             }
           //  pArray(small_left);
            pw.println(nu);
         }
    	
       }
private static void update(int node,int low,int high,int ind,int val){
    	 if(ind < low || ind > high){
             return;
         }
		
		if(low==high){
     		st[node]=val;
     		return;
    	 }
    	 
    	int mid=(low+high)/2;
    	if(low<= ind && ind<=mid){
    		update(2*node, low, mid, ind, val);
    	}else{
    		update(2*node+1, mid+1, high, ind, val);
    	}
     st[node]= st[2*node] + st[2*node+1];
}
    
private static int query(int node,int low,int high,int qlow,int qhigh){
    	
    	if(qlow>high || qhigh<low){
    		return 0;
    	}
    	 
    	if(qlow<=low && qhigh>=high){
        	
    		return st[node];
    	}
    	
    int mid=(low+high)/2;
    int ans1=query(2*node, low, mid, qlow, qhigh);
    int ans2=query(2*node+1, mid+1, high, qlow, qhigh);
    
    return ans1 + ans2;
    }
    
    

 // To Get Input
 // Some Buffer Methods
  
     		     	
     		    	public static void InputReader(InputStream stream1) {
     		    		stream = stream1;
     		    	}
  
     		    	private static boolean isWhitespace(int c) {
     		    		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
     		    	}
  
     		    	private static boolean isEndOfLine(int c) {
     		    		return c == '\n' || c == '\r' || c == -1;
     		    	}
  
     		    	private static int read() {
     		    		if (numChars == -1)
     		    			throw new InputMismatchException();
     		    		if (curChar >= numChars) {
     		    			curChar = 0;
     		    			try {
     		    				numChars = stream.read(buf);
     		    			} catch (IOException e) {
     		    				throw new InputMismatchException();
     		    			}
     		    			if (numChars <= 0)
     		    				return -1;
     		    		}
     		    		return buf[curChar++];
     		    	}
  
     		    	private static int nextInt() {
     		    		int c = read();
     		    		while (isSpaceChar(c))
     		    			c = read();
     		    		int sgn = 1;
     		    		if (c == '-') {
 							sgn = -1;
 							c = read();
						}	
						int res = 0;
						do {
 							if (c < '0' || c > '9')
 								throw new InputMismatchException();
							res *= 10;
							res += c - '0';
     		    			c = read();
     		    		} while (!isSpaceChar(c));
     		    		return res * sgn;
     		    	}
  
     		    	private static long nextLong() {
     		    		int c = read();
     		    		while (isSpaceChar(c))
     		    			c = read();
     		    		int sgn = 1;
     		    		if (c == '-') {
 							sgn = -1;
 							c = read();
						}
						long res = 0;
						do {
							if (c < '0' || c > '9')
 								throw new InputMismatchException();
							res *= 10;
						    res += c - '0';
     		    			c = read();
     		    		} while (!isSpaceChar(c));
     		    		return res * sgn;
     		    	}
  
     		    	private static String nextToken() {
     		    		int c = read();
     		    		while (isSpaceChar(c))
     		    			c = read();
     		    		StringBuilder res = new StringBuilder();
     		    		do {
     		    			res.appendCodePoint(c);
     		    			c = read();
     		    		} while (!isSpaceChar(c));
     		    		return res.toString();
     		    	}
  
     		    	private static String nextLine() {
     		    		int c = read();
     		    		while (isSpaceChar(c))
     		    			c = read();
     		    		StringBuilder res = new StringBuilder();
     		    		do {
     		    			res.appendCodePoint(c);
     		    			c = read();
     		    		} while (!isEndOfLine(c));
     		    		return res.toString();
     		    	}
  
     		    	private static int[] nextIntArray(int n) {
     		    		int[] arr = new int[n];
     		    		for (int i = 0; i < n; i++) {
     		    			arr[i] = nextInt();
     		    		}
     		    		return arr;
     		    	}
  
     		    	private static long[][] next2dArray(int n, int m) {
     		    		long[][] arr = new long[n][m];
     		    		for (int i = 0; i < n; i++) {
     		    			for (int j = 0; j < m; j++) {
     		    				arr[i][j] = nextLong();
     		    			}
     		    		}
     		    		return arr;
     		    	}
     		    	private static char[][] nextCharArray(int n,int m){
     		    		char [][]c=new char[n][m];
     		    		for(int i=0;i<n;i++){
     		    			String s=nextLine();
     		    			for(int j=0;j<s.length();j++){
     		    				c[i][j]=s.charAt(j);
     		    			}
     		    		}
     		    		return c;
     		    	}
  
     		    	private static long[] nextLongArray(int n) {
     		    		long[] arr = new long[n];
     		    		for (int i = 0; i < n; i++) {
     		    			arr[i] = nextLong();
     		    		}
     		    		return arr;
     		    	}
  
     		    	private static void pArray(int[] arr) {
     		    		for (int i = 0; i < arr.length; i++) {
     		    			pw.print(arr[i] + " ");
     		    		}
     		    		pw.println();
     		    		return;
     		    	}
  
     		    	private static void pArray(long[] arr) {
     		    		for (int i = 0; i < arr.length; i++) {
     		    			pw.print(arr[i] + " ");
     		    		}
     		    		pw.println();
     		    		return;
     		    	}
  
     		    	private static void pArray(boolean[] arr) {
     		    		for (int i = 0; i < arr.length; i++) {
     		    			pw.print(arr[i] + " ");
     		    		}
     		    		pw.println();
     		    		return;
     		    	}
  
     		    	private static boolean isSpaceChar(int c) {
     		    		if (filter != null)
     		    			return filter.isSpaceChar(c);
     		    		return isWhitespace(c);
     		    	}
  
     		    	private interface SpaceCharFilter {
     		    		public boolean isSpaceChar(int ch);
     		    	}
    
}

