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.*;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author admin
 */
public class P900C {
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int[] arry = new int[n];
        for(int i = 0; i < n; ++i)
        {
            arry[i] = in.nextInt();
        }
        Hashtable<Integer, Integer> result = new Hashtable();
        int secMax = 0;
        int max = arry[0];
        result.put(max, 0);
        for(int i = 1; i < n; ++i)
        {
            if(arry[i] > max)
            {
                secMax = max;
                max = arry[i];   
                result.put(max, 0);
            }
            else if(arry[i] > secMax)
            {
                secMax = arry[i];
                int value = result.get(max);
                result.replace(max, value + 1);
            }
        }
        Set<Map.Entry<Integer, Integer>> r = result.entrySet();
        int minNum = arry[0];
        int maxV = result.get(minNum);
        for(Map.Entry<Integer, Integer> entry : r)
        {
            //out.print(entry.getKey() + ";" + entry.getValue()+ "\n");
            if(entry.getValue() > maxV)
            {
                minNum = entry.getKey();
                maxV = entry.getValue();
            }
            if(entry.getValue() == maxV && entry.getKey() < minNum)
            {
                minNum = entry.getKey();
            }
        }
        //out.print(minNum);
       //out.print(maxV);
       if(maxV == 1)
       {
           //out.print("max == 1\n");
            Arrays.sort(arry);
            out.print(arry[0]);
       }
       else if(maxV == 0)
       {
           //out.print("max == 0\n");
           Arrays.sort(arry);
           boolean flag = false;
           for(int i = 0; i < n; ++i)
           {
               if(!result.containsKey(arry[i]))
               {
                   out.print(arry[i]);
                   flag = true;
                   break;
               }
           }
           if(flag == false)
               out.print(arry[0]);
       }
       else
       {
            out.print(minNum);
       }
           
           

        out.close();
    }
}
