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 C implements Runnable{
	public static void main (String[] args) {new Thread(null, new C(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");

		int n = fs.nextInt();
		int[] a = fs.nextIntArray(n);
//		int n = new Random().nextInt(10)+1;
//		if(n == 1) n++;
//		int[] a = new int[n];
//		boolean[] used = new boolean[n];
//		for(int i = 0; i < n; i++) {
//			int x = new Random().nextInt(n);
//			while(used[x]) {
//				x = new Random().nextInt(n);
//			}
//			used[x] = true;
//			a[i] = ++x;
//		}
		if(n == 1) {
			System.out.println(1);
			return;
		}
		int[] pos = new int[n+1];
		for(int i = 0; i < n; i++) pos[a[i]] = i+1;
		Fenwick_Tree ft = new Fenwick_Tree(n), right = new Fenwick_Tree(n);
		boolean[] rec = new boolean[n+1], poss = new boolean[n+1];
		int idx = 0, small = n+1;
		for(int i = n; i > 0; i--) {
			int left = ft.sum(pos[i]);
			if(left == 0) {
				rec[pos[i]] = true;
				idx++;
			}
			else if(left == 1) {
				poss[pos[i]] = true;
			}
			else {
				small = Math.min(small, i);
			}
			ft.update(pos[i], 1);
		}
		
		int[] vals = new int[idx+1];
		int sum = 0, iidx = 0;
		for(int i = 1; i <= n; i++) {
			if(rec[i]) {
//				System.out.println(i + " " + iidx + " " + sum);
				vals[iidx++] = sum;
				sum = 0;
			}
			else if(poss[i]) {
				sum++;
			}
		}
		vals[iidx] = sum;
		
//		System.out.println(Arrays.toString(rec));
//		System.out.println(Arrays.toString(poss));
//		System.out.println(Arrays.toString(vals));
//		System.out.println(small);

		iidx = 1;
		ArrayList<Integer> check = new ArrayList<>();
		int max = 0, res = -1;
		for(int i = 1; i <= n; i++) {
			if(!rec[i]) continue;
			if(vals[iidx] > 1 && vals[iidx] > max) {
				max = vals[iidx];
				res = a[i-1];
			}
			else if(vals[iidx] > 1 && vals[iidx] == max) {
				res = Math.min(res, a[i-1]);
			}
			else if(vals[iidx] == 1) {
				check.add(i);
			}
			iidx++;
		}
//		System.out.println("RRR " + res);
		if(res < 0) {
			res = n+1;
//			System.out.println(check);
			for(int i = 0; i < check.size(); i++) {
				int lim = n+1;
				if(i + 1 < check.size()) {
					lim = check.get(i+1);
				}
				int x = check.get(i);
				for(int j = x+1; j < lim; j++) {
					if(poss[j]) {
						res = Math.min(res, a[j-1]);
					}
				}
			}
			for(int i = 1; i <= n; i++) {
				if(!poss[i] && !rec[i]) res = Math.min(res, a[i-1]);
			}
			if(res == n+1) res = 1;
		}
//		System.out.println("R" + res);
//		System.out.println(Arrays.toString(a));
//		out.println(brute(a, n));
		out.println(res);
		
		
		out.close();
	}
	
	int brute (int[] a, int n) {
		int max = -1, res = n+1;
		for(int rem = 0; rem < n; rem++) {
			int cnt = 0;
			for(int i = 0; i < n; i++) {
				boolean g = true;
				if(i == rem) continue;
				for(int j = i-1; j >= 0; j--) {
					if(j == rem) continue;
					if(a[j] > a[i]) {
						g = false;
						break;
					}
				}
				if(g) cnt++;
			}
//			System.out.println(rem + " " + a[rem] + " " + cnt);
			if(cnt > max) {
				max = cnt;
				res = a[rem];
			}
			else if(cnt == max) {
				res = Math.min(res, a[rem]);
			}
		}
		return res;
	}
	
	class Fenwick_Tree {
		
		int[] bit;
		int n;
		
		public Fenwick_Tree(int a) {
			n = a + 1;
			bit = new int[n];
		}
		
		//Remember that when querying a sum to query the 1-based index of the value.
		
		void update (int index, int val) {
			while(index < n) {
				bit[index] += val;
				index += (index & (-index));
			}
		}
		
		int sum (int index) {
			int sum = 0;
			while(index > 0) {
				sum += bit[index];
				index -= (index & (-index));
			}
			return sum;
		}
	}
	
	class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		public FastScanner() {
			try	{
				br = new BufferedReader(new InputStreamReader(System.in));
				//                br = new BufferedReader(new FileReader("testdata.out"));
				st = new StringTokenizer("");
			} catch (Exception e){e.printStackTrace();}
		}
		public String next() {
			if (st.hasMoreTokens())	return st.nextToken();
			try {st = new StringTokenizer(br.readLine());}
			catch (Exception e) {e.printStackTrace();}
			return st.nextToken();
		}
		public int nextInt() {return Integer.parseInt(next());}
		public long nextLong() {return Long.parseLong(next());}
		public double nextDouble() {return Double.parseDouble(next());}

		public String nextLine() {
			String line = "";
			try {line = br.readLine();}
			catch (Exception e) {e.printStackTrace();}
			return line;
		}
		public Integer[] nextIntegerArray(int n) {
			Integer[] a = new Integer[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
		public char[] nextCharArray() {return nextLine().toCharArray();}
	}

}