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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Asgar Javadov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        FastWriter out = new FastWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, FastWriter out) {
            int n = in.nextInt();
            int[] a = in.readIntArray(n);

            int[][] dp = new int[n][2];
            dp[0][0] = a[0];

            for (int i = 1; i < n; i++) {
                if (a[i] > dp[i - 1][0]) {
                    dp[i][0] = a[i];
                    dp[i][1] = dp[i - 1][0];
                } else {
                    dp[i][0] = dp[i - 1][0];
                    dp[i][1] = Math.max(dp[i - 1][1], a[i]);
                }
            }

            int[] count = new int[n + 1];
            for (int i = 0; i < n; ++i) {
                if (a[i] < dp[i][1]) {
                    count[i] = 2;
                } else if (a[i] < dp[i][0]) {
                    count[i] = 1;
                }
            }

            int[] delete = new int[n + 1];
            for (int i = 0; i < n; ++i) {
                if (count[i] == 1) {
                    delete[dp[i][0]]++;
                }
            }

            int records = 0;
            for (int i = 0; i < n; i++) {
                if (count[i] == 0)
                    records++;
            }

            int idx = -1, max = -1;
            for (int i = 0; i < n; ++i) {
                int temp = 0;
                if (count[i] == 0) {
                    temp = MathUtils.max(temp, records - 1 + delete[a[i]]);
                } else {
                    temp = MathUtils.max(temp, records + delete[a[i]]);
                }

                if (max < temp) {
                    max = temp;
                    idx = a[i];
                } else if (max == temp && idx > a[i]) {
                    idx = a[i];
                }
            }

            out.println(idx);


//        int small = n + 1;
//    	for (int i = 0; i < n; ++i) {
//    	    if (count[i] >= 1 && small > a[i]) {
//    	        small = a[i];
//            }
//        }
//        int ans = -1, id = -1;
//        for (int i = 0; i < n; i++) {
//            if (ans < delete[a[i]]) {
//                ans = delete[a[i]];
//                id = i;
//            } else if (ans == delete[a[i]] && a[id] > a[i]) {
//                id = i;
//            }
//        }
//
//        if (ans > 1 || ans == 0)
//            out.println(a[id]);
//        else if (small <= n){
//            out.println(Math.min(a[id], small));
//        } else {
//            out.println(a[id]);
//        }
        }

    }

    static class FastWriter extends PrintWriter {
        public FastWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public FastWriter(Writer writer) {
            super(writer);
        }

        public FastWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

        public int[] readIntArray(int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
                array[i] = nextInt();
            return array;
        }

    }

    static class MathUtils {
        public static int max(int... args) {
            int res = args[0];
            for (int i = 1; i < args.length; ++i)
                if (res < args[i])
                    res = args[i];
            return res;
        }

    }
}

