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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class C {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int [] ind = new int[n];
		int [] num = new int[n];
		int [] a = new int[n];
		boolean [] b = new boolean[n];
		int tot = 0;
		TreeSet<Integer> set = new TreeSet<>();
		for (int i = 0; i < num.length; i++) {
			a[i] = sc.nextInt();
			ind[a[i]-1] = i;
			Integer tmp = set.size() > 0?set.last():null;
			if(tmp == null || tmp < a[i])
			{
				tot++;
				b[i] = true;
 			}
			else{
				int tmp2 = tmp;
				tmp = set.lower(tmp);
				if(tmp == null || tmp < a[i])
				{
					num[ind[tmp2-1]]++;
				}
			}
			set.add(a[i]);
		}
		int max = tot-1 + num[0], idx = 0;
		for (int i = 1; i < a.length; i++) {
			int ans = tot + (b[i]?-1+num[i]:0);
			if(ans > max){
				max = ans;
				idx = i;
			}
			else if(ans == max && a[i] < a[idx]){
				idx = i;
			}
		}
//		System.out.println(max);
		out.println(a[idx]);
		out.flush();
		out.close();
	}

	static class Scanner {
		BufferedReader bf;
		StringTokenizer st;

		public Scanner(InputStream i) {
			bf = new BufferedReader(new InputStreamReader(i));

		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(bf.readLine());
			return st.nextToken();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
	}
}