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.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.max;

public class Main {
    BufferedReader br;
    PrintWriter pw;
    StringTokenizer st;
    long LNF = Long.parseLong("9223372036854775807");
    String s;
    long mod = (long) (1e9 + 7);

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

    void solve() throws IOException {
        int n = nextInt();
        int mx = 0;
        int a[] = new int[n];
        boolean r[] = new boolean[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
            if (a[i] > mx) {
                r[i] = true;
            }
            mx = max(mx, a[i]);
        }
        int x[] = new int[n];
        TreeSet<p> tr = new TreeSet<>();
        tr.add(new p(a[0], 0));
        for (int i = 1; i < n; i++) {
            p f = tr.pollFirst();
            if ((tr.size() == 0 || a[i] > tr.first().a) && a[i] < f.a) {
                x[f.b]++;
            }
            tr.add(f);
            tr.add(new p(a[i], i));
        }
        for (int i = 0; i < n; i++) {
            if (r[i]) x[i]--;
        }
        int ind = 0;
        for (int i = 0; i < n; i++) {
            if (x[i] > x[ind]) {
                ind = i;
            } else if (x[i] == x[ind] && a[i] < a[ind]) {
                ind = i;
            }
        }
        pw.print(a[ind]);
    }

    long p(int n, int k) {
        if (n == 0 && k == 0) return 1;
        if (n > 0 && k == 0) return 0;
        if (k <= n) {
            return (p(n, k - 1) + p(n - k, k)) % mod;
        } else {
            return p(n, n);
        }
    }

    void run() {
        try {
//            br = new BufferedReader(new FileReader("linear.in"));
            br = new BufferedReader(new InputStreamReader(System.in));
//            pw = new PrintWriter(new FileWriter("linear.out"));
            pw = new PrintWriter(new OutputStreamWriter(System.out));
            solve();
            pw.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

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

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

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

    class p implements Comparable<p> {
        int a, b;

        public p(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(p o) {
            return o.a - a;
        }
    }

}