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 Main {
    public static void main(String[] args) throws Exception {
        InputStream inputStream;
        OutputStream outputStream;
        if(System.getProperty("ONLINE_JUDGE") == null) {
            File input = new File("inp.txt");
            File ouput = new File("out.txt");
            inputStream = new FileInputStream(input);
            outputStream = new FileOutputStream(ouput);
        }
        else {
            inputStream = System.in;
            outputStream = System.out;
        }
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        int nTest = 1;
        solver.solve(nTest, in, out);
        out.close();
    }

    static class Task {

        int n;
        int[] a;
        int[] c;
        int[] pos;
        int[] maxPre;
        int[] L;
        int[] R;
        int[] f;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            a = new int[n + 2];
            maxPre = new int[n + 2];
            L = new int[n + 2];
            R = new int[n + 2];
            f = new int[n + 2];
            pos = new int[n + 2];
            c = new int[n + 2];
            maxPre[0] = -1;
            for(int i = 1;i <= n;++i){
                a[i] = in.nextInt();
                pos[a[i]] = i;
            }
            for(int i = 1;i <= n;++i){
                maxPre[i] = Math.max(maxPre[i - 1],a[i]);
                L[i] = L[i - 1] + (a[i] > maxPre[i - 1] ? 1 : 0);
            }
            for(int i = n;i >= 1;--i){
                R[i] = R[i + 1] + (int)(a[i] > maxPre[i - 1] ? 1 : 0);
            }
            FenwickTree ft = new FenwickTree();
            for(int i = 1;i <= n;++i){
                c[i] = ft.rsq(a[i] - 1);
                ft.update(a[i],1);
            }
            for(int i = 1;i <= n;++i){
                if(c[i] != i - 2)continue;
                ++f[maxPre[i - 1]];
            }
            int ans = -1,value = -1;
            for(int i = 1;i <= n;++i){
                if(ans < L[pos[i] - 1] + f[i] + R[pos[i] + 1]) {
                    value = i;
                    ans = L[pos[i] - 1] + f[i] + R[pos[i] + 1];
                }
            }
            out.print(value);
        }

        public class FenwickTree{
            int[] tree;
            FenwickTree(){
                tree = new int[n + 2];
            }
            void update(int node,int val){
                for(;node <= n;node += node & (-node))
                    tree[node]+=val;
            }
            int rsq(int node){
                int ret = 0;
                for(;node > 0;node -= node & (-node))
                    ret+=tree[node];
                return ret;
            }

        }

    }

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

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

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

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}
