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

import static java.lang.Math.abs;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.util.Arrays.copyOf;
import static java.util.Arrays.fill;
import static java.util.Arrays.sort;
import static java.util.Collections.reverseOrder;
import static java.util.Collections.sort;

public class Main {
    private FastScanner in;
    private PrintWriter out;

    private void solve() throws IOException {
        solveC();
    }

    private void solveA() throws IOException {
        int n = in.nextInt(), l = 0, r = 0, x, y;
        for (int i = 0; i < n; i++) {
            x = in.nextInt();
            y = in.nextInt();
            if (x > 0)
                r++;
            else
                l++;
        }
        out.println(l < 2 || r < 2 ? "Yes" : "No");
    }

    private void solveB() throws IOException {
        long a = in.nextLong(), b = in.nextLong(), c = in.nextLong(), cur, hash, cnt = 0;
        HashSet<Long> set = new HashSet<>();
        while (true) {
            a *= 10;
            cur = a / b;
            a %= b;
            hash = cur * 1000000 + a;
            cnt++;
            if (set.contains(hash)) {
                out.println(-1);
                return;
            } else if (cur == c) {
                out.println(cnt);
                return;
            } else {
                set.add(hash);
            }
        }

    }

    private void solveC() throws IOException {
        int n = in.nextInt();
        Record[] records = new Record[n];
        int max = 0, p;
        for (int i = 0; i < n; i++) {
            p = in.nextInt();
            max = max(max, p);
            records[i] = new Record(p, i, max == p);
        }
        Record[] cntRecords = new Record[n + 1];
        for (Record i : records)
            cntRecords[i.value] = i;

        TreeSet<Integer> set = new TreeSet<>();
        Integer first, second;
        for (int i = n; i > 0; i--) {
            if (!cntRecords[i].record) {
                first = set.lower(cntRecords[i].pos);
                if (first == null) {
                    second = null;
                } else {
                    second = set.lower(first);
                }
                if (second == null && first != null) {
                    records[first].cnt++;
                }
            }
            set.add(cntRecords[i].pos);
        }
        int value = Integer.MAX_VALUE, cnt = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            if (records[i].cnt > cnt || (records[i].cnt == cnt && records[i].value < value)) {
                cnt = records[i].cnt;
                value = records[i].value;
            }
        }
        out.println(value);
    }

    private void solveD() throws IOException {

    }

    private void solveE() throws IOException {

    }

    class Record {
        int value, pos, cnt;
        boolean record;

        Record(int d, int i, boolean b) {
            value = d;
            pos = i;
            record = b;
            cnt = b ? -1 : 0;
        }
    }

    class FastScanner {
        StringTokenizer st;
        BufferedReader br;

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

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        boolean hasNext() throws IOException {
            return br.ready() || (st != null && st.hasMoreTokens());
        }

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

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

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

        String nextLine() throws IOException {
            return br.readLine();
        }

        boolean hasNextLine() throws IOException {
            return br.ready();
        }
    }

    private void run() throws IOException {
        in = new FastScanner(System.in); // new FastScanner(new FileInputStream(".in"));
        out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(".out"));
        solve();
        out.flush();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}
