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 com.sun.jmx.snmp.agent.SnmpUserDataFactory;

import java.io.*;
import java.sql.Blob;
import java.util.*;

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);
        TaskB solver = new TaskB();
        solver.solve(in, out);
        out.close();
    }

    private static class TaskB {


        public void solve(InputReader in, PrintWriter out) {

            int n;
            n = in.nextInt();
            int arr[] = new int[n];
            int dp[] = new int[n];

            for (int i = 0; i < n; i++)
                arr[i] = in.nextInt();

            if (n == 1) {
                System.out.println(arr[0]);
                return;
            }

            int maxi = arr[0];
            dp[0] = maxi;

            for (int i = 1; i < n; i++) {
                if (arr[i] > maxi)
                    maxi = arr[i];
                else dp[i] = maxi;
            }

            List<Integer>[] list = new ArrayList[n + 1];
            for (int i = 1; i <= n; i++)
                list[i] = new ArrayList<>();

            int maxi1 = Math.max(arr[0], arr[1]);
            int maxi2 = Math.min(arr[0], arr[1]);

            if (arr[0] > arr[1])
                list[arr[1]].add(maxi1);

            for (int i = 2; i < n; i++) {
                if (arr[i] < maxi2 && arr[i] < maxi1) {
                    list[arr[i]].add(maxi1);
                    list[arr[i]].add(maxi2);
                } else if (arr[i] > maxi2 && arr[i] < maxi1) {
                    list[arr[i]].add(maxi1);
                    maxi2 = arr[i];
                } else {
                    maxi2 = maxi1;
                    maxi1 = arr[i];
                }
            }

            int res[] = new int[n + 1];

            for (int i = 1; i <= n; i++)
                if (list[i].size() == 1)
                    res[list[i].get(0)]++;

            maxi = Integer.MIN_VALUE;
            int value = 1;

            for (int i = 0; i < n; i++) {
                int temp = 0;
                if (arr[i] >= dp[i]) temp++;
                if (res[arr[i]] - temp > maxi) {
                    maxi = res[arr[i]] - temp;
                    value = arr[i];
                } else if (res[arr[i]] - temp == maxi) {
                    if (arr[i] < value) value = arr[i];
                }
            }

            System.out.println(value);

        }
    }

    private static class InputReader {
        StringTokenizer st;
        BufferedReader br;

        public InputReader(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public InputReader(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

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

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

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public boolean ready() {
            try {
                return br.ready();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}