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.IOException;
import java.util.Scanner;
import java.util.Stack;

public class Monkey {
	
	public static int get(int[] cumsum, int l, int r) {
		if(l >= cumsum.length || r < 0) {
			return 0;
		}
		int ans = cumsum[r];
		if(l > 0) {
			ans -= cumsum[l-1];
		}
		return ans;
	}
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		//BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] max = new int[n];
		int[] record = new int[n];
		int[] a = new int[n];
		for(int i=0; i<n; i++) {
			a[i] = in.nextInt();
			
			if(i == 0) {
				max[i] = a[i];
				record[i] = 1;
			}
			else {
				max[i] = Math.max(a[i], max[i-1]);
				if(a[i] > max[i-1]) {
					record[i] = 1;
				}
				record[i] += record[i-1];
			}
		}
		
		int bestAns = -1;
		int bestIdx = -1;
		
		Stack<Integer> stack = new Stack<>();
		
		for(int i=n-1; i>=0; i--) {
			int add = 0;
			while(stack.size() > 0 && stack.peek() < a[i]) {
				int cur = stack.pop();
				if(i == 0 || cur > max[i-1]) {
					add++;
				}
			}
			stack.push(a[i]);
			int curAns = add + get(record, 0, i-1) + get(record, i+1, n-1);
			if(curAns > bestAns || (curAns == bestAns && a[i] < bestIdx)) {
				bestAns = curAns;
				bestIdx = a[i];
			}
		}
		
		System.out.println(bestIdx);
		
	
	}

}
