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.util.Arrays;
import java.util.Scanner;
/*


10
1 2 3 9 4 5 10 6 7 8

12
1 2 3 7 4 5 6 10 8 9 11 12


 */


public class c {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		
//		int[] randomPerm = randomPerm(N);
//		System.out.println(Arrays.toString(randomPerm));
		
		int[] arr = new int[N];
		int[] backwards = new int[N+1];
		for(int n=0;n<N;n++){
			arr[n] = in.nextInt();
//			arr[n] = randomPerm[n];
			backwards[arr[n]] = n;
		}
		
		// how many maxes do we have right now?
		int numMaxes = numMaxesWithout(N, arr, -1);
		int[] numMaxesWoThis = new int[N];
		Arrays.fill(numMaxesWoThis, numMaxes);
		
		// for all j, let's
		// count the number of times
		// arr[i] is highest when arr[j]
		// is second highest
		int[] count = new int[N];
		Wavelet waveyMcWaveFace = new Wavelet(arr);
		for(int n = 0; n < N; n++){
			// this range is (n+1) in length
			// second highest will be nth lowest
			int highest = waveyMcWaveFace.kthLowest(n+1, 0, n+1);
			
			if(highest == arr[n]){
				numMaxesWoThis[n]--;
			}
			
			if(n == 0) continue;

			int secHighest = waveyMcWaveFace.kthLowest(n, 0, n+1);
			if(secHighest == arr[n]){
				count[backwards[highest]]++;
			}
		}
		
		for(int n=0;n<N;n++){
			numMaxesWoThis[n] += count[n];
		}
		
//		System.out.println(Arrays.toString(numMaxesWoThis));
		
		int max = -1;
		int dexOfMax = 0;
		for(int n = 0; n < N; n++){
			if(numMaxesWoThis[n] > max || (numMaxesWoThis[n] == max && arr[n] < arr[dexOfMax])){
				max = numMaxesWoThis[n];
				dexOfMax = n;
			}
		}
		
		System.out.println(arr[dexOfMax]);
//		System.out.println(arr[naiveSol(N, arr, backwards)]);
	}
	
	static int naiveSol(int N, int[] arr, int[] backwards){
		int max = -1;
		int dexOfMax = -1;
		for(int n=0;n<N;n++){
			int prop = numMaxesWithout(N, arr, n);
			if(prop > max || (prop == max && arr[n] < arr[dexOfMax])){
				max = prop;
				dexOfMax = n;
			}
		}
		return dexOfMax;
	}
	
	static int numMaxesWithout(int N, int[] arr, int woThisDex){
		int count = 0;
		int high = 0;
		for(int n=0;n<N;n++){
			if(n == woThisDex) continue;
			if(high < arr[n]){
				high = arr[n];
				count++;
			}
		}
		return count;
	}
	
	static int[] randomPerm(int len){
		int[] arr = new int[len];
		for(int i = 0; i < len; i++){
			arr[i] = i+1;
		}
		
		for(int i = 0; i < len; i++){
			int choose = i + (int)(Math.random() * (len - i));
			int temp = arr[i];
			arr[i] = arr[choose];
			arr[choose] = temp;
		}
		
		return arr;
	}
	
	static class Wavelet{
		int l = 2147483647, h = -2147483648;
		int[] arr, ldex, hdex;
		Wavelet low = null, high = null;
		Wavelet(int[] arr){
			this.arr = arr;
			for(int i : arr){
				l = Math.min(l, i);
				h = Math.max(h, i);
			}
			ldex = new int[arr.length + 1];
			hdex = new int[arr.length + 1];
			int mid = l + (h - l) / 2;
			for(int n = 0; n < arr.length; n++){
				if(arr[n] > mid){
					ldex[n+1] = ldex[n];
					hdex[n+1] = hdex[n] + 1;
				}
				else{
					ldex[n+1] = ldex[n] + 1;
					hdex[n+1] = hdex[n];
				}
			}
			if(l == h) return;
			int[] larr = new int[ldex[arr.length]];
			int[] harr = new int[hdex[arr.length]];
			for(int n=0;n<arr.length;n++){
				if(hdex[n] == hdex[n+1]) larr[ldex[n]] = arr[n];
				else harr[hdex[n]] = arr[n];
			}
			low = new Wavelet(larr);
			high = new Wavelet(harr);
		}
		// range [ll, rr)
		int kthLowest(int k, int ll, int rr){
			if(l == h){
				return arr[ll + k-1];
			}
			if(ldex[rr] - ldex[ll] >= k){
				return low.kthLowest(k, ldex[ll], ldex[rr]);
			}
			return high.kthLowest(k - ldex[rr] + ldex[ll], hdex[ll], hdex[rr]);
		}
	}
}
