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.
"""
NTC here
"""
from sys import setcheckinterval, stdin, setrecursionlimit
setcheckinterval(1000)
setrecursionlimit(10**7)
 
# print("Case #{}: {} {}".format(i, n + m, n * m))
 
 
def iin(): return int(stdin.readline())
 
 
def lin(): return list(map(int, stdin.readline().split()))

from collections import defaultdict
n=iin()
a=lin()
if n==1:
    print(a[0])
    exit()
rm=a[0]
rm1=-1
sl=defaultdict(int)
sl[rm]=0
record=[0]*n
record[0]=1
for i in range(1,n):
    #print(a[i],rm,rm1)
    if a[i]<rm:
        sl[rm]+=1
        if rm1!=-1 and a[i]<rm1:
            sl[rm]-=1
    else:
        record[i]=1
    if rm>a[i]:rm1=max(rm1,a[i])
    else:
        rm1=rm
        rm=a[i]
#print(record,sl)
sol=sum(record)
ans=[a[0],sol-record[0]+sl[a[0]]]
for i in range(n):
    x=sol-record[i]+sl[a[i]]
    #print(x,a[i])
    if x>ans[1]:
        ans=[a[i],x]
    elif x==ans[1]:
        ans[0]=min(a[i],ans[0])
print(ans[0])