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.*;
import java.util.Map.Entry;
import java.lang.Math;
import java.math.BigInteger;

public class L {
	long INF = Long.MAX_VALUE / 3;
	int MODULO = 1000 * 1000 * 1000 + 2346;

	class Edge {
		int to;
		long dist;

		Edge(int to, long dist) {
			this.to = to;
			this.dist = dist;
		}
	}

	class Vertex implements Comparable<Vertex> {
		int index;
		long dist;

		Vertex(int index, long dist) {
			this.index = index;
			this.dist = dist;
		}

		@Override
		public int compareTo(Vertex other) {
			// TODO Auto-generated method stub
			return Long.compare(this.dist, other.dist);
		}
	}

	List<Edge>[] graph;
	boolean[] used;
	long maxDist = 0;
	long sum = 0;
	void solve() throws IOException {
		int n = rI();
		int[] a = new int[n];
		Fenwik f = new Fenwik(a);
		int[] ind = new int[n];
		int[] prefMax = new int[n];
		for(int i=0; i<n; ++i){
			a[i] = rI()-1;
			if(i==0){
				prefMax[i] = a[i];
			}else{
				prefMax[i] = Math.max(prefMax[i-1], a[i]);
			}
			ind[a[i]] = i;
		}
		int[] ans = new int[n];
		boolean[] isRec = new boolean[n];
		for(int i=0; i<n; ++i){
			
			long sum = f.getSum(n-a[i]-1);
			f.inc(n-1-a[i], 1);
			//out.println(sum);
			if(sum == 0){
				isRec[i] = true;
				ans[i]--;
			}
			if(sum == 1){
				int  max = prefMax[i];
				ans[ind[max]]++;
			}
		}
		/*
		for(int i: ans){
			out.print(i+" ");
		}
		out.println();*/
		int max = -2;
		int ansInd = 0;
		int count = 0;
		for(int i=0; i<n; ++i){
			//max = Math.max(ans[i], max);
			if(max==ans[i]){
				if(a[ansInd]>a[i]){
					ansInd = i;
				}
				count++;
			}
			if(max<ans[i]){
				max = ans[i];
				ansInd = i;
				count = 1;
			}
		}
		//out.println(count);
		
		out.println(a[ansInd]+1);
	}
	
	class Fenwik{
		private long[] t;
		private int length;
		
		Fenwik(int[] a){
			this.length = a.length+100;
			this.t = new long[length];
			for(int i=0;i<a.length;++i){
				this.inc(i, a[i]);
			}
		}
		
		void inc(int i, int delta){
			for(; i<this.length; i=i|(i+1)){
				this.t[i] += delta;
			}
		}
		
		long getSum(int r){
			long sum = 0;
			
			for(;r>=0;r=(r&(r+1))-1){
				sum+= this.t[r];
			}
			
			return sum;
		}
	}
	
	class SegmentTree {
		int[] t;

		SegmentTree(int[] a) {
			t = new int[a.length * 4];
			build(a, 1, 1, a.length - 1);
		}

		void build(int[] a, int v, int tl, int tr) {
			if (tr == tl) {
				t[v] = a[tl];
				return;
			}
			int mid = (tr + tl) / 2;
			build(a, 2 * v, tl, mid);
			build(a, 2 * v + 1, mid + 1, tr);
			t[v] = Math.max(t[2 * v], t[2 * v + 1]);
		}

		int getMax(int v, int tl, int tr, int l, int r) {
			if (l > r)
				return (int) -INF;
			if (tr == tl) {
				return t[v];
			}
			if (tl == l && tr == r) {
				return t[v];
			}

			int mid = (tr + tl) / 2;
			int max1 = getMax(2 * v, tl, mid, l, Math.min(r, mid));
			int max2 = getMax(2 * v + 1, mid + 1, tr, Math.max(l, mid + 1), r);
			return Math.max(max1, max2);
		}

		void update(int v, int tl, int tr, int value, int pos) {
			if (tl == tr) {
				t[v] = value;
				return;
			}
			int mid = (tl + tr) / 2;
			if (pos <= mid) {
				update(2 * v, tl, mid, value, pos);
			} else {
				update(2 * v + 1, mid + 1, tr, value, pos);
			}
			t[v] = Math.max(t[2 * v], t[2 * v + 1]);
		}
	}

	int checkBit(int mask, int bit) {
		return (mask >> bit) & 1;
	}

	public static void main(String[] args) throws IOException {

		new L().run();
	}

	boolean isLower(char a) {
		return ((int) a) >= 97 ? true : false;
	}

	int[][] STEPS = { { 0, 1 }, { 1, 0 }, { -1, 0 }, { 0, -1 } };

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;
	Random rnd = new Random();
	static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	L() throws FileNotFoundException {

		try {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		} catch (Exception e) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		}

		tok = new StringTokenizer("");
	}

	long checkBit(long mask, int bit) {
		return (mask >> bit) & 1;
	}

	// ======================================================

	// ======================================================
	void run() throws IOException {
		solve();
		out.close();
	}

	char[] reverseCharArray(char[] arr) {
		char[] ans = new char[arr.length];
		for (int i = 0; i < arr.length; ++i) {
			ans[i] = arr[arr.length - i - 1];
		}
		return ans;
	}

	int sqrt(double m) {
		int l = 0;
		int r = 1000000000 + 9;
		int i = 1000;
		while (r - l > 1) {
			int mid = (r + l) / 2;
			if (mid * mid > m) {
				r = mid;
			} else {
				l = mid;
			}
		}
		return l;
	}

	int countPow(int m, int n) {
		int ans = 0;
		while (m % n == 0 && m > 0) {
			ans++;
			m /= n;
		}
		return ans;
	}

	long binPow(long a, long b, long m) {
		if (b == 0) {
			return 1;
		}
		if (b % 2 == 1) {
			return ((a % m) * (binPow(a, b - 1, m) % m)) % m;
		} else {
			long c = binPow(a, b / 2, m);
			return (c * c) % m;
		}

	}

	int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	long pow(long x, long k) {
		long ans = 1;
		for (int i = 0; i < k; ++i) {
			ans *= x;
		}
		return ans;
	}

	// ////////////////////////////////////////////////////////////////////

	String delimiter = " ";

	String readLine() throws IOException {
		return in.readLine();
	}

	String rS() throws IOException {
		while (!tok.hasMoreTokens()) {
			String nextLine = readLine();
			if (null == nextLine)
				return null;

			tok = new StringTokenizer(nextLine);
		}

		return tok.nextToken(delimiter);
	}

	int rI() throws IOException {
		return Integer.parseInt(rS());
	}

	long rL() throws IOException {
		return Long.parseLong(rS());
	}

	double rD() throws IOException {
		return Double.parseDouble(rS());
	}

	int[] rA(int b) {
		int a[] = new int[b];
		for (int i = 0; i < b; i++) {
			try {
				a[i] = rI();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return a;
	}

	int[] readSortedIntArray(int size) throws IOException {
		Integer[] array = new Integer[size];

		for (int index = 0; index < size; ++index) {
			array[index] = rI();
		}
		Arrays.sort(array);

		int[] sortedArray = new int[size];
		for (int index = 0; index < size; ++index) {
			sortedArray[index] = array[index];
		}

		return sortedArray;
	}

	int[] sortedIntArray(int size, int[] array) throws IOException {
		for (int index = 0; index < size; ++index) {
			array[index] = rI();
		}
		Arrays.sort(array);

		int[] sortedArray = new int[size];
		for (int index = 0; index < size; ++index) {
			sortedArray[index] = array[index];
		}

		return sortedArray;
	}
}