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.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Collections;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            if (n == 2) {
                int x = in.nextInt(), y = in.nextInt();
                out.println(1);
                return;
            }
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            ArrayList<Integer> max2 = new ArrayList<>();
            int points[] = new int[n + 1];
            boolean unused[] = new boolean[n + 1];
            boolean unusedFound = false;
            for (int i = 0; i < n; i++) {
                if (max2.size() < 2) { // first two iterations only
                    if (max2.size() == 1) {
                        int x = max2.get(0);
                        if (x > a[i])
                            points[x]++;
                    }
                    max2.add(a[i]);
                    Collections.sort(max2);
                } else {
                    int small = max2.get(0);
                    int big = max2.get(1);
                    if (a[i] > small && a[i] < big)
                        points[big]++;
                    else if (a[i] < small) {
                        unused[a[i]] = true;
                        unusedFound = true;
                    }
                    max2.add(a[i]);
                    Collections.sort(max2);
                    max2.remove(0);
                }
            }
            int ans = -1, maxPoints = -1;
//        out.println(Arrays.toString(points));
            for (int i = 1; i < n + 1; i++) {
                if (points[i] > maxPoints) {
                    ans = i;
                    maxPoints = points[i];
                }
            }
            if (unusedFound) {
                int ansRec = 0, unusedRec = 0;
                int ansMax = 0, unusedMax = 0;
                for (int i = 0; i < n; i++) {
                    if (a[i] != ans) {
                        if (a[i] > ansMax) {
                            ansMax = a[i];
                            ansRec++;
                        }
                    }
                    if (a[i] > unusedMax) {
                        unusedMax = a[i];
                        unusedRec++;
                    }
                }
                if (unusedRec >= ansRec) {
                    for (int i = 1; i < n + 1; i++) {
                        if (unused[i]) {
                            out.println(i);
                            return;
                        }
                    }
                }
            }
            out.println(ans);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

