After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first.

Help guys determine the winner photo by the records of likes.


-----Input-----

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the total likes to the published photoes. 

The second line contains n positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 1 000 000), where a_{i} is the identifier of the photo which got the i-th like.


-----Output-----

Print the identifier of the photo which won the elections.


-----Examples-----
Input
5
1 3 2 2 1

Output
2

Input
9
100 200 300 200 100 300 300 100 200

Output
300



-----Note-----

In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second). 

Thus, the winner is the photo with identifier 2, as it got:  more likes than the photo with id 3;  as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier.

Difficulty: interview

Starter code:

Solutions:
n = int(input())
a = [int(x) for x in input().split()]
score = dict()
sup, winner = -2**31, None
for v in a:
    score[v] = score[v] + 1 if v in score else 1
    if score[v] > sup:
        sup, winner = score[v], v
print(winner)


n = int(input())
a = list(map(int, input().split()))

d = dict()
d[0] = 0
mx = 0
for i in a:
    d[i] = d.get(i, 0) + 1
    if d[i] > d[mx]:
        mx = i
print(mx)

n = input()
has = {}
best = -1
has[best]=-1
ar = [int(x) for x in input().split()]
for x in ar:
    if x not in has:
        has[x]=1
    else:
        has[x]+=1
    if has[x] > has[best]:
        best = x
print(best)


n = int(input())
a = map(int, input().split())
s = dict()
ans = -1
pos = 1
for i in a:
    if i in s:
        s[i] += 1
    else:
        s[i] = 1
    if (ans < s[i]):
        pos, ans = i, s[i]

print(pos)

#!/bin/python
import collections
import random
import sys
try:
    from tqdm import tqdm
except:
    def tqdm(iterable):
        return iterable


__taskname = ''
if __taskname:
    sys.stdin = open(__taskname + '.in')
    sys.stdout = open(__taskname + '.out', 'w')

n = int(input())
ans = -1
d = {-1: -1}
for a in map(int, input().split()):
    d[a] = d.get(a, 0) + 1
    if d[a] > d[ans]:
        ans = a
print(ans)


n = int(input())
arr = [int(x) for x in input().split()]

m = -1
ans = -1
d = dict()

for i in arr:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
        
    if m == -1 or d[i] > m:
        m = d[i]
        ans = i
        
print(ans)

import math
import random


def read_ints():
    return [int(x) for x in input(' ').split()]


def main():
    n, = read_ints()
    A = [(int(x), i) for i, x in enumerate(input(' ').split())]
    A.sort()
    A.append((10**10, n))
    max_id, max_len, max_last = -1, -1, -1
    curr_id, curr_len, curr_last = -1, -1, -1
    for a, i in A:
        if a == curr_id:
            curr_len, curr_last = curr_len+1, i
        else:
            if curr_len >= max_len:
                if curr_len > max_len or curr_last < max_last:
                    max_id, max_len, max_last = curr_id, curr_len, curr_last
            curr_id, curr_len, curr_last = a, 1, i
    print(max_id)

def __starting_point():
    main()
__starting_point()

from collections import defaultdict
n = input()
likes = defaultdict(int)
maxlikes = 0
idx = 0
for time, photoid in enumerate(input().split()):
    likes[photoid] +=1
    if likes[photoid] > maxlikes:
        maxlikes = likes[photoid]
        idx = photoid
print(idx)


like_count = int(input())
likes = input().split()
counter = {}
most_liked = ''
max_like_count = 0
for like in likes:
    if like in counter:
        counter[like] += 1
    else:
        counter[like] = 1
    if max_like_count < counter[like]:
        most_liked = like 
        max_like_count = counter[like]
print(int(most_liked))

n = int(input())
d = {}
a = list(map(int, input().split()))
for i in range(n):
    if a[i] not in d:
        d[a[i]] = (1, n - i)
    else:
        d[a[i]] = (d[a[i]][0] + 1, n - i)
print(sorted(d.items(), key = lambda x: x[1])[-1][0])

n = int(input())
a = list(map(int, input().split()))

max_n = 1
cnt = dict()
cnt[a[0]] = 1
max_ = a[0]
for i in range(1, n):
    cur_n = a[i]
    if cur_n not in cnt:
        cnt[cur_n] = 0
    cnt[cur_n] += 1
    if cnt[cur_n] > max_n:
        max_n = cnt[cur_n]
        max_ = cur_n
print(max_)


photos = {}
n = input()
likes = input().split()
m = {
    "id": 0,
    "q": 0,
}
for p_id in likes:
    if p_id in photos:
        photos[p_id] += 1
    else:
        photos[p_id] = 1
    if photos[p_id] > m["q"]:
        m["q"] = photos[p_id]
        m["id"] = p_id

print(m["id"])

n = int(input())
ai = list(map(int,input().split()))
photos = [[0]*1000000 for i in range(2)]
for i in range(n):
    photos[0][ai[i]-1] += 1
    photos[1][ai[i]-1] = i
max_likes = max(photos[0])
min_ind = 1000000
ans = 0
for i in range(1000000):
    if photos[0][i] != 0 and max_likes == photos[0][i]:
        if min_ind > photos[1][i]:
            min_ind = photos[1][i]
            ans = i+1
print(ans)


n = int(input())
a = [0]*1000001
m = 0

l = list(map(int, input().split()))
for i in range(n):
    a[l[i]] += 1
    if a[l[i]] > m:
        m = a[l[i]]
        j = l[i]
print(j)

n = int(input())
A = [0] * 1000001
idx = 1
for i in list(map(int, input().split())):
    A[i] += 1
    if A[i] > A[idx]:
        idx = i
print(idx)

n = int(input())
a = input().split()
b = set(a)
maximum = -1
maximum_id = []
for i in b:
    x = a.count(i)
    if x > maximum:
        maximum_id = [int(i)]
        maximum = x
    elif x == maximum:
        maximum_id.append(int(i))
a = a[::-1]
maximum = -1
answer = -1
for i in maximum_id:
    x = a.index(str(i))
    if x > maximum:
        answer = i
        maximum = x
print(answer)

n = int(input())
l = list(map(int, input().split()))
d1 = dict()
d = dict()
s = set()
s1 = set()
for i in l:
    if i in s:
        d[i] += 1
    else:
        d[i] = 1
    s.add(i)

max1 = 0
for i in d:
    max1 = max(max1, d[i])
for i in l:
    if i in s1:
        d1[i] += 1
    else:
        d1[i] = 1
    s1.add(i)
    if d1[i] == max1:
        print(i)
        break

from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
max_i = -1
max_n = -1
ans = Counter()
for x in arr:
    ans[x] += 1
    if ans[x] > max_n:
        max_i = x
        max_n = ans[x]
print(max_i)


n = int(input())
data = list(map(int, input().split())) 

lst = dict() 
tme = dict() 
for i in range(n): 
    if data[i] in list(lst.keys()): 
        lst[data[i]] += 1         
    else: 
        lst[data[i]] = 1 
    tme[data[i]] = i 

ps = -1 
mx = -1 
time = -1 
for i in list(lst.keys()):
    if lst[i] > mx: 
        mx = lst[i] 
        time = tme[i] 
        ps = i 
    elif lst[i] == mx: 
        if time > tme[i]: 
            time = tme[i] 
            ps = i 

print(ps)


n = int(input())
likes_str = input()
likes = likes_str.split()
photo = {}
max_val = 0
max_num = 0
for i in range(0, n):
    photo_num = int(likes[i])
    if photo_num in photo:
        photo[photo_num] += 1
    else:
        photo[photo_num] = 1
    if photo[photo_num] > max_val:
        max_val = photo[photo_num]
        max_num = photo_num

print(max_num)

n = int(input())
x = [int(i) for i in input().split()]
data = dict()
for i in range(0,n):
    if not (x[i] in data):
        data[x[i]]=[1,i]
    else:
        data[x[i]] = [data[x[i]][0]+1, i]
t = list(data.items());
t.sort(key=lambda x: (-x[1][0], x[1][1]))
print(t[0][0])

total = input()
timeline = input().split()

photos = len(set(timeline))

numberOfLikes = dict.fromkeys(timeline, 0)
max = -1
for pic in timeline:
    numberOfLikes[pic]+=1
    if numberOfLikes[pic]>max:
        max = numberOfLikes[pic]
        res = pic
print(res)

n = int(input())
line = input().split()
maxi = line[0]
mas = {}
mas[maxi] = 1
for i in range(1, n):
    a = line[i]
    if not a in mas:
        mas[a] = 1
    else:
        mas[a] += 1
    if (mas[a] > mas[maxi]):
        maxi = a
print(maxi)


likes=int(input())
mas=input().split()
d={}
for i in mas:
	if i in d :
		d[i] += 1
	else :
		d[i] = 1
maxx = max(d.values())
res = 0
for i in range (likes - 1, -1,  -1) :
	k = mas[i]
	if d[mas[i]] == maxx :
		res = mas[i]
		d[mas[i]] = 0
print(res)

from functools import reduce
     
a=int(input())
b=list([int(m) for m in input().split(' ')])

m=max([len(list([m for m in b if m==i])) for i in b]) #количество вхождений

v={a:0 for a in b}

for i in b:
    v[i]+=1
    if v[i]== m:
        print(i)
        return