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

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

    static class PartialMaximums {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = in.nextIntArray(1, n);
            HashMap<Integer, Integer> occ = new HashMap<>();
            TreeSet<Integer> memo = new TreeSet<>();
            boolean[] isRecord = new boolean[n + 1];
            int maxPrev = 0;
            int count = 0;
            for (int e : arr) {
                occ.put(e, 0);
            }
            for (int i = 1; i <= n; i++) {
                if (arr[i] > maxPrev) {
                    isRecord[i] = true;
                    count++;
                    occ.put(arr[i], -1);
                } else {
                    Integer greater = memo.ceiling(arr[i]);
                    if (greater != null && greater.equals(memo.last())) {
                        occ.put(greater, occ.get(greater) + 1);
                    }
                }
                maxPrev = Math.max(arr[i], maxPrev);
                memo.add(arr[i]);
            }
            int answer = arr[1];
            for (int i = 1; i <= n; i++) {
                if (occ.get(arr[i]) > occ.get(answer)) {
                    answer = arr[i];
                } else if (occ.get(arr[i]).equals(occ.get(answer))) {
                    answer = Math.min(arr[i], answer);
                }
            }
            out.println(answer);
        }

    }

    static class InputReader {
        private StringTokenizer tokenizer;
        private BufferedReader reader;

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        private void fillTokenizer() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }

        public String next() {
            fillTokenizer();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextIntArray(int offset, int length) {
            int[] arr = new int[offset + length];
            for (int i = offset; i < offset + length; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

    }
}

