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 sys
# import bisect
# from collections import deque

# from types import GeneratorType
# def bootstrap(func, stack=[]):
#     def wrapped_function(*args, **kwargs):
#         if stack:
#             return func(*args, **kwargs)
#         else:
#             call = func(*args, **kwargs)
#             while True:
#                 if type(call) is GeneratorType:
#                     stack.append(call)
#                     call = next(call)
#                 else:
#                     stack.pop()
#                     if not stack:
#                         break
#                     call = stack[-1].send(call)
#             return call
#     return wrapped_function

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))

def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')

n = int(ri())
a = Ri()

maxx, premaxx = -1,-1
pospremaxx = -1
posmaxx = -1
lis = [0]*n
for i in range(n):
    if a[i] > maxx:
        premaxx = maxx
        maxx = a[i]
        lis[i]-=1
        posmaxx = i

    elif a[i] > premaxx:
        # print(a[i], premaxx, maxx)
        lis[posmaxx]+=1
        premaxx = a[i]
        pospremaxx = i

# print(lis)

ans = -1
posans = -1
for i in range(n):
    if lis[i] >= ans:
        if lis[i] == ans:
            if a[posans] > a[i]:
                posans = i
                ans = lis[i]
        else:
            posans = i
            ans = lis[i]
print(a[posans])
            