Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.

First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.


-----Input-----

In first line there is one integer n (1 ≤ n ≤ 2·10^5) — number of cafes indices written by Vlad.

In second line, n numbers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 2·10^5) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.


-----Output-----

Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.


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

Output
3

Input
6
2 1 2 2 4 1

Output
2



-----Note-----

In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. 

In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.

Difficulty: MEDIUM

Solutions:
n = int(input())
lst = list(map(int, input().split()))
lst1 = []
s = {}
for i in range(n):
	s[lst[i]] = i + 1
k = list(s.keys())
i = list(s.values())
print(k[i.index(min(i))])


n = int(input())
a = list(map(int, input().split()))
a.reverse()
b = set()
for i in a:
	b.add(i)
k = 0
for i in a:
	if i in b:
		k = i
		b.remove(i)
print(k)


n = int(input())
a = list(map(int, str(input()).split()))
b = [-1 for i in range(max(a) + 1)]
m = 10 ** 6
for i in range(n):
	b[a[i]] = i
for i in range(len(b)):
	if b[i] != -1:
		if b[i] <= m:
			v = a[b[i]]
			m = b[i]
print(v)


n = int(input())
array = [int(i) for i in input().split()]
last_time = dict()
for i in range(n - 1, -1, -1):
	if not array[i] in last_time:
		last_time[array[i]] = i
res = zip(last_time.keys(), last_time.values())
res = sorted(res, key=lambda x: n - x[1], reverse=True)
print(res[0][0])


def max_dict(d: dict):
	max_key = 0
	max_elem = -float('inf')
	for i in d:
		if d[i] > max_elem:
			max_elem = d[i]
			max_key = i
	return max_key
n = int(input())
a = list(map(int, input().split()))
b = {x: float('inf') for x in a}
for i in range(len(a)):
	b[a[i]] = min(len(a) - i - 1, b[a[i]])
print(max_dict(b))


n = int(input())
d = dict()
a = [int(x) for x in input().split()]
for i in range(n):
	d[a[i]] = i
ans = -1
m = 10 ** 7
for i in d.keys():
	if d[i] < m:
		ans = i
		m = d[i]
print(ans)


UselessNumber = int(input())
Cafes = list(map(int, input().split()))
Cafes.reverse()
BestResult = [0, 0]
AlreadyRead = {}
for i in range(len(Cafes)):
	if Cafes[i] not in AlreadyRead:
		BestResult = [Cafes[i], i]
		AlreadyRead[Cafes[i]] = 0
print(BestResult[0])


n = int(input())
a = [int(x) for x in input().split()]
d = {}
for i in range(n):
	d[a[i]] = i
mx = 10 ** 20
otv = 0
for x in d.items():
	if x[1] < mx:
		mx = x[1]
		otv = x[0]
print(otv)


n = int(input())
a = [int(x) for x in input().split()]
visited = []
vs = set()
i = n - 1
while i >= 0:
	if a[i] not in vs:
		vs.add(a[i])
		visited.append(a[i])
	i -= 1
print(visited[-1])


n = int(input())
visited = list(map(int, input().split()))
notVisied = set(visited)
for i in range(n - 1, -1, -1):
	if len(notVisied) == 1:
		break
	if visited[i] in notVisied:
		notVisied.remove(visited[i])
for elm in notVisied:
	print(elm)


n = int(input())
a = list(map(int, input().split()))
a = a[::-1]
w = set(a)
r = set()
for i in range(len(a)):
	if a[i] not in r:
		r.add(a[i])
	if r == w:
		print(a[i])
		raise SystemExit


import math
n = int(input())
a = [int(x) for x in input().split()]
N = 2 * 10 ** 5 + 1
mark = [math.inf] * N
for i in range(n):
	mark[a[i]] = i
ind = None
for i in range(N):
	if mark[i] != math.inf and (ind is None or mark[ind] > mark[i]):
		ind = i
print(ind)


N = int(input())
texts = [0] * N
texts = input().split()
ends = set()
count = 0
for i in range(N):
	if not int(texts[N - i - 1]) in ends:
		ends.add(int(texts[N - i - 1]))
		count = texts[N - i - 1]
print(int(count))


n = int(input())
a = list(map(int, input().split()))
set_a = set(a)
if len(set_a) == 1:
	print(a[0])
	exit()
for i in range(n):
	cur = a[~i]
	if cur in set_a:
		set_a.remove(cur)
		if len(set_a) == 1:
			print(list(set_a)[0])
			break


f = lambda : map(int, input().split())
n = int(input())
l = list(f())[::-1]
m = len(set(l))
dup = set()
for i in l:
	dup.add(i)
	if len(dup) == m:
		print(i)
		break


input()
a = [int(i) for i in input().split()]
s = set(a)
i = len(a) - 1
while len(s) != 1:
	if a[i] in s:
		s.remove(a[i])
	i -= 1
print(list(s)[0])


n = int(input())
a = [int(x) for x in input().split()][::-1]
c = set(a)
for i in a:
	if len(c) != 1:
		c -= {i}
print(*c)


n = int(input())
list1 = list(map(int, input().split()))
b = [False] * 10 ** 6
ans = 0
for i in range(n - 1, -1, -1):
	if b[list1[i]] == False:
		ans = list1[i]
		b[list1[i]] = True
print(ans)


n = int(input())
l = list(map(int, input().split()))
lt = {}
for i in range(n - 1, -1, -1):
	if l[i] in lt:
		pass
	else:
		lt[l[i]] = i
m = min(list(lt.values()))
print(l[m])


n = int(input())
cans = list(map(int, input().split()))
c = set()
num = 0
for i in range(n - 1, -1, -1):
	if not cans[i] in c:
		c.add(cans[i])
		num = cans[i]
print(num)


n = int(input())
arr = list(map(int, input().split()))
was = ['N'] * 200500
for i in range(n):
	was[arr[i]] = i
m = 99999999999
ind = 0
for i in range(200500):
	if was[i] != 'N':
		if was[i] < m:
			m = was[i]
			ind = i
print(ind)


n = input()
stol = input()
stol = stol.split(' ')
nums = {}
for i in range(0, len(stol)):
	nums[stol[i]] = [i, len(stol) - i]
dif = []
max = -1
imax = 0
fl = 0
for num in nums:
	if max < nums[num][1]:
		max = nums[num][1]
		imax = num
print(imax)


n = int(input())
a = list(map(int, input().split()))
a.reverse()
b = set()
ans = 0
for i in range(len(a)):
	if a[i] not in b:
		ans = a[i]
	b.add(a[i])
print(ans)


n = int(input())
count = set()
cafe = 0
r = [int(x) for x in input().split()]
r = r[::-1]
for i in r:
	if i not in count:
		cafe = i
		count.add(i)
print(cafe)


n = int(input())
s = input().split()
a = [0] * (2 * 10 ** 5 + 1)
Max = 0
M = ''
for i in range(len(s) - 1, -1, -1):
	s[i] = int(s[i])
	if a[s[i]] == 0:
		a[s[i]] = len(s) - i
		if Max < a[s[i]]:
			Max = a[s[i]]
			M = s[i]
print(M)


n = int(input())
a = list(map(int, input().split()))
m = max(a)
z = []
for i in range(m + 1):
	z.append(200001)
for i in range(n):
	z[a[i]] = i
print(a[min(z)])


n = int(input())
m = list(map(int, input().split(' ')))
c = set()
for i in m[::-1]:
	if i not in c:
		c.add(i)
		ans = i
print(ans)


n = int(input())
data = list(map(int, input().split()))
was = {}
for i in range(n):
	was[data[i]] = i
print(min(was.keys(), key=was.get))


input()
a = [int(i) for i in input().split()]
b = {}
for i in range(len(a)):
	b[a[i]] = i
print(a[min(b.values())])


n = int(input())
a = input().split()
b = set(a)
a = a[::-1]
for i in a:
	if len(b) != 1:
		if i in b:
			b.remove(i)
	else:
		print(*b)
		break


n = int(input())
arr = list(map(int, input().split()))
was = [10000000000000000000] * (2 * 10 ** 5 + 10)
for i in range(n):
	was[arr[i]] = i
mn = 10 ** 9
mn_i = -1
for el in arr:
	if was[el] < mn:
		mn = was[el]
		mn_i = el
print(mn_i)


n = int(input())
A = list(map(int, input().split()))
c = dict()
for i in range(n):
	a = A[i]
	c[a] = i
mini = 100000000000000
numb = 0
for i in c:
	if c[i] < mini:
		numb = i
		mini = c[i]
print(numb)


n = int(input())
a = list(map(int, input().split()))
s = set()
last = 0
for i in range(len(a) - 1, -1, -1):
	if not a[i] in s:
		last = a[i]
		s.add(a[i])
print(last)


n = int(input())
a = list(map(int, input().split()))
d = {}
for p in range(n):
	d[a[p]] = p
out = min(d, key=lambda x: d[x])
print(out)


n1 = int(input())
arr1 = list(reversed(input().split()))
a1 = len(arr1) - len(set(arr1))
d1 = dict()
k1 = 1
for i in arr1:
	if i not in d1.keys():
		d1[i] = k1
	k1 += 1
maxim1 = 0
for (i, j) in d1.items():
	if j >= maxim1:
		res1 = i
		maxim1 = j
print(res1)


input()
a = input().split()
b = {}
i = 0
while i < len(a):
	b[a[i]] = i
	i += 1
print(a[min(b.values())])


n = int(input())
s = list(map(int, input().split()))
d = [1000000000000] * (max(s) + 4)
for i in range(n):
	d[s[i]] = i
print(d.index(min(d)))


sl = int(input())
time = list(map(int, input().split()))
last = dict()
rs = time[0]
tmp = sl
dem = 0
for i in time:
	dem += 1
	last[i] = dem
for (i, j) in last.items():
	if j < tmp:
		rs = i
		tmp = j
print(rs)


n = int(input())
data = {}
s = [int(x) for x in input().split(' ')]
for i in range(n):
	data[s[i]] = i
min_val = min(data.values())
min = [key for (key, value) in data.items() if value == min_val][0]
print(min)


n = int(input())
lst = []
d = {}
k = -1
for x in input().split():
	k += 1
	d[x] = k
m = 0
for (x, y) in d.items():
	if y < n:
		n = y
		m = x
print(m)


n = int(input())
ar = [int(x) for x in input().split()]
s = set()
for i in range(len(ar) - 1, -1, -1):
	if ar[i] not in s:
		p = ar[i]
		s.add(ar[i])
print(p)


INF = 10 ** 6
n = int(input())
arr = list(map(int, input().split()))
pos = dict()
stol = dict()
for i in range(n - 1, -1, -1):
	stol = arr[i] - 1
	if pos.get(stol) is None:
		pos[stol] = n - i
ans = arr[0] - 1
for stol in pos.keys():
	if pos[stol] > pos[ans]:
		ans = stol
print(ans + 1)


n = int(input())
a = reversed([int(x) for x in input().split()])
ans = -1
used = [False] * (2 * 10 ** 5 + 13)
for elem in a:
	if not used[elem]:
		used[elem] = True
		ans = elem
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
b = {x: 0 for x in a}
for i in range(len(a)):
	b[a[i]] = i
minim = -1
minpos = len(a) + 1
for i in a:
	if b[i] < minpos:
		minpos = b[i]
		minim = i
print(minim)


n = int(input())
a = list(map(int, input().split()))
b = {}
for i in range(len(a)):
	b[a[i]] = i
print(a[min(b.values())])


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
	d[a[i]] = i
c = list(d.items())
c.sort(key=lambda x: x[1])
answ = c[0][0]
print(answ)


number = int(input())
a = list(input().split())
s = set()
m = a[-1]
a = a[::-1]
for i in a:
	if not i in s:
		s.add(i)
		m = i
print(m)


import re
in1 = int(input())
in2 = re.split('\\s', input())
test = {}
count = 0
for x in in2:
	test[x] = count
	count += 1
print(min(test, key=test.get))


n = int(input())
cafes = list(map(int, input().split()))
lastChecked = {}
for i in range(len(cafes)):
	lastChecked[cafes[i]] = i
print(cafes[min(lastChecked.values())])


n = int(input())
c = [int(i) for i in input().split()]
m = []
for i in range(max(c) + 1):
	m.append(-1)
for i in range(n):
	m[c[i]] = n - i - 1
max = -1
pos = 0
for i in range(len(m)):
	if m[i] > max:
		max = m[i]
		pos = i
print(pos)


n = int(input())
k = input().split()
b = [200001 for i in range(200001)]
m = 0
for i in range(n):
	b[int(k[i])] = m
	m += 1
print(k[min(b)])


n = int(input())
num = list(map(int, input().split()))
used = [False] * 200001
for i in range(len(num) - 1, -1, -1):
	if not used[num[i]]:
		used[num[i]] = True
		ans = num[i]
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = set(a)
for i in range(n - 1, -1, -1):
	b.discard(a[i])
	if not b:
		print(a[i])
		break


n = int(input())
indices = list(map(int, input().strip().split(' ')))
visits = {}
for (i, index) in enumerate(indices):
	visits[index] = i
last_visit = n - 1
last_index = indices[-1]
for (index, visit) in visits.items():
	if visit < last_visit:
		last_index = index
		last_visit = visit
print(last_index)


n = int(input())
s = [0 for i in range(200001)]
s[200000] = 200001
k = 0
for i in input().split():
	k += 1
	x = int(i)
	s[x - 1] = k
mn = -1
for i in range(200001):
	if s[i] != 0 and s[i] < s[mn]:
		mn = i
print(mn + 1)


n = int(input())
s = input().split()
a = set()
s = s[::-1]
pam = ' '
pam = s[0]
a.add(s[0])
for i in s:
	if i != pam and i not in a:
		pam = i
		a.add(i)
print(pam)


n = int(input())
a = []
for i in range(200001):
	a.append(1000000)
numbers = input().split()
for i in range(n):
	temp = int(numbers[i])
	a[temp] = i
i_min = 0
for i in range(1, 200001):
	if a[i] < a[i_min]:
		i_min = i
print(i_min)


n = int(input())
sl = dict()
s = input().split()
for i in range(n):
	sl[int(s[i])] = i
c = n
for j in sl:
	if sl[j] < c:
		c = sl[j]
		t = j
print(t)


n = int(input())
a = list(map(int, input().split()))
b = [1000000] * 1000000
for i in range(n):
	b[a[i]] = i + 1
min = 20000000
num = 0
for i in range(1000000):
	if b[i] != -1:
		if b[i] < min:
			min = b[i]
			num = i
print(num)


n = int(input())
arr = list(reversed(input().split()))
a = len(arr) - len(set(arr))
dictit = dict()
k = 1
for i in arr:
	if i not in dictit.keys():
		dictit[i] = k
	k += 1
MAXIM = 0
for (i, j) in dictit.items():
	if j >= MAXIM:
		res = i
		MAXIM = j
print(res)


n = int(input())
a = list(map(int, input().split()))
l = set()
a = a[::-1]
s = len(set(a))
for i in range(n):
	l.add(a[i])
	if len(l) == s:
		print(a[i])
		break


(n, a, d) = (int(input()), list(map(int, input().split())), {})
for i in range(n):
	d[a[i]] = i
print(a[min(d.values())])


resh = 0
m = set()
x = int(input())
a = list(map(int, input().split()))
j = x - 1
while j >= 0:
	if not a[j] in m:
		resh = a[j]
		m.add(a[j])
	j -= 1
print(resh)


n = int(input())
m = list(map(int, input().split()))
a = [0] * (max(m) + 1)
res = 0
for i in range(n - 1, -1, -1):
	if a[m[i]] == 0:
		a[m[i]] = 1
		res = m[i]
print(res)


n = int(input())
data = list(map(int, input().split()))
d = dict()
if n == 1:
	print(data[0])
	exit()
d[data[-1]] = True
de = dict()
for i in range(n):
	if data[i] not in de:
		de[data[i]] = True
k = len(de)
for i in range(n - 2, -1, -1):
	if data[i] not in d:
		if len(d) == k - 1:
			print(data[i])
			exit()
		else:
			d[data[i]] = True
print(data[0])


kol = int(input())
date = list(map(int, input().split()))
dict = {}
for i in range(len(date)):
	dict[date[i]] = i
min = 1000000
for i in dict:
	if dict[i] < min:
		min = dict[i]
		last = i
print(last)


n = int(input())
a = list(map(int, input().split()))
a.reverse()
s = set()
t = -1
for i in range(n):
	if a[i] in s:
		k = 0
	else:
		m = i
		t = a[i]
		s.add(a[i])
print(t)


input()
h = {a: i for (i, a) in enumerate(map(int, input().split()))}
print(min(h, key=h.get))


N = int(input())
cafes = list(map(int, input().split()))
indices = set(cafes)
met = set()
for i in range(N - 1, -1, -1):
	met.add(cafes[i])
	if len(met) == len(indices):
		print(cafes[i])
		break


d = dict()
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	d[a[i]] = i
d = sorted(d.values())
print(a[d[0]])


n = int(input())
l = [*map(int, input().split())]
tmp = {}
Ans = None
for i in range(n - 1, -1, -1):
	if tmp.get(l[i], -1) == -1:
		tmp[l[i]] = 1
		Ans = l[i]
	else:
		pass
print(Ans)


n = int(input())
a = list(map(int, input().split()))
l = [-1 for i in range(2 * 10 ** 5 + 10)]
for i in range(n):
	l[a[i]] = i
min_pos = 3 * 10 ** 5
min_s = -1
for i in range(2 * 10 ** 5 + 5):
	if l[i] == -1:
		pass
	elif l[i] < min_pos:
		min_pos = l[i]
		min_s = i
print(min_s)


n = int(input())
visited = input().split()[::-1]
cafes = set(visited)
for i in visited:
	if len(cafes) == 1:
		print(cafes.pop())
		break
	if i in cafes:
		cafes.remove(i)


import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
n = ii()
a = li()
b = [0] * (2 * 10 ** 5 + 1)
for i in range(n):
	b[a[i]] = i + 1
ans = 2 * 10 ** 5
for i in range(2 * 10 ** 5 + 1):
	if b[i] != 0:
		ans = min(ans, b[i] - 1)
print(a[ans])


n = int(input())
stol = [int(x) for x in input().split()]
bil = set()
for i in range(n - 1, -1, -1):
	if stol[i] not in bil:
		res = stol[i]
		bil.add(stol[i])
print(res)


n = int(input())
a = [int(s) for s in input().split()]
a1 = set()
for i in a:
	a1.add(i)
for i in range(n - 1, -1, -1):
	if len(a1) > 1:
		a1.discard(a[i])
	else:
		for i in a1:
			print(i)
		break


n = int(input())
data = [int(i) for i in input().split()]
data.reverse()
s = set()
last = -1
for i in data:
	if i not in s:
		s.add(i)
		last = i
print(last)


n = int(input())
lst = list(map(int, input().split()))
s = set(lst)
i = n - 1
while len(s) > 1:
	if lst[i] in s:
		s.remove(lst[i])
	i -= 1
print(s.pop())


n = int(input())
L = list(map(int, input().split()))
d = {}
for i in range(n):
	if L[i] in d:
		d[L[i]] += 1
	else:
		d[L[i]] = 1
v = len(d)
d.clear()
for i in range(n - 1, -1, -1):
	if L[i] in d:
		d[L[i]] += 1
	else:
		d[L[i]] = 1
	if len(d) == v:
		print(L[i])
		exit()


import collections
n = int(input())
save = [0] * (2 * 10 ** 5 + 5)
mark = [0] * (2 * 10 ** 5 + 5)
data = list(map(int, input().split()))
for i in range(n):
	save[data[i]] = i
	mark[data[i]] = 1
minn = 10 ** 9 + 1
place = 0
for i in range(len(save)):
	if mark[i] == 1 and save[i] < minn:
		minn = save[i]
		place = i
print(place)


n = int(input())
a = [int(i) for i in input().split()]
st = [2 * 10 ** 5] * (max(a) + 1)
mins = 2 * 10 ** 5
for j in range(n):
	st[a[j]] = j
for i in range(max(a) + 1):
	if st[i] < mins:
		mins = st[i]
		f = i
print(f)


n = int(input())
p = list(map(int, input().split()))
s = set(p)
i = n - 1
while len(s) != 1:
	if p[i] in s:
		s.remove(p[i])
	i -= 1
print(*s)


n = int(input())
A = list(map(int, input().split()))
count = 0
B = []
for q in range(300000):
	B.append(n + 1)
for q in range(len(A)):
	B[A[q]] = q
print(B.index(min(B)))


input()
arr = list(map(int, input().split()))[::-1]
a = 0
setarr = set(arr)
for i in arr:
	if i in setarr:
		if len(setarr) > 1:
			setarr.remove(i)
		else:
			print(i)
			break


n = int(input())
a = list(map(int, input().split()))
s = set()
for x in a[::-1]:
	if x not in s:
		s.add(x)
		ans = x
print(ans)


_ = int(input())
ts = [int(s) for s in input().split()]
d = {}
for (i, t) in enumerate(ts):
	d[t] = i
mint = None
for t in d.keys():
	if mint == None or d[t] < d[mint]:
		mint = t
print(mint)


n = int(input())
all_a = list((int(x) for x in input().split(' ')))
counter = {}
for a in range(0, n):
	counter[str(all_a[a])] = a
print(max(counter, key=lambda a: n - counter[a]))


import sys, math
sys.setrecursionlimit(10 ** 8)
t = int(input())
arr = list(map(int, input().split()))
arr = arr[::-1]
d = {i: 0 for i in set(arr)}
l = len(d)
for i in arr:
	if d[i] == 0:
		d[i] += 1
		if l == 1:
			print(i)
		l -= 1
	else:
		d[i] += 1


input()
a = list(map(int, input().split()))
n = len(set(a))
b = [0] * 200001
k = 0
for i in a[::-1]:
	if b[i] == 0:
		k += 1
		b[i] = 1
	if k == n:
		print(i)
		break


from collections import Counter
n = int(input())
li = list(map(int, input().split()))
li = li[::-1]
print(list(Counter(li))[-1])


n = int(input())
m = list(map(int, input().split()))
r = set(m)
t = []
x = len(m) - 1
while len(r):
	if m[x] in r:
		t.append(m[x])
		r.remove(m[x])
	x -= 1
print(t[-1])


n = int(input())
a = [int(i) for i in input().split()]
d = len(set(a))
flag = 0
l = set()
for i in range(len(a) - 1, -1, -1):
	l.add(a[i])
	if len(l) == d - 1:
		flag = i - 1
print(a[flag])


def solution():
	n = int(input())
	arr = [int(i) for i in input().split(' ')]
	(k, v) = (float('inf'), 0)
	d = {}
	for (i, x) in enumerate(arr):
		d[x] = i
	for (val, key) in d.items():
		if k > key:
			k = key
			v = val
	print(v)
solution()


n = int(input())
cafe = list(map(int, input().split()))
array = set()
last = -1
for i in range(len(cafe) - 1, -1, -1):
	if cafe[i] not in array:
		array.add(cafe[i])
		last = i
print(cafe[last])


n = int(input())
a = dict()
s = input()
g = s.split(' ')
for i in range(0, n):
	a[int(g[i])] = i
c = n
for key in a:
	if a[key] < c:
		c = a[key]
		p = key
print(p)


n = int(input())
A = list(map(int, input().split()))
D = {}
for i in range(n):
	D[A[i]] = i
B = sorted(list(D.items()), key=lambda x: x[1])
print(B[0][0])


import itertools
import re
import math
import getpass
import sys
debug = False
files = False
if getpass.getuser() == 'frohe':
	debug = True
if debug and files:
	sys.stdin = open('test.in')

def ria():
	return [int(i) for i in input().split()]
n = ria()[0]
ar = ria()
mp = {}
for i in ar:
	mp[i] = 0
for (n, i) in enumerate(ar):
	mp[i] = n
mini = ar[0]
for i in mp:
	if mp[mini] > mp[i]:
		mini = i
print(mini)


N = int(input())
times = {}
v = [int(x) - 1 for x in input().split()]
for (t, a) in enumerate(v):
	times[a] = t
(mina, mint) = next(iter(times.items()))
for (a, t) in times.items():
	if t < mint:
		mint = t
		mina = a
print(mina + 1)


n = int(input())
a = [int(i) for i in input().split()]
b = [0] * (max(a) + 1)
k = len(set(a))
t = 0
p = 0
for i in range(n):
	b[a[i]] = n - i
print(b.index(max(b)))


length = int(input())
canteens = list(map(int, input().split(' ')))
last = canteens[-1]
array = set()
for i in range(length - 1, -1, -1):
	if canteens[i] not in array:
		array.add(canteens[i])
		last = i
print(canteens[last])


n = int(input())
a = [int(i) for i in input().split()]
d = dict()
minN = 200000.0 + 10
ans = 0
for i in range(n):
	d[a[i]] = i
for key in d:
	if d[key] < minN:
		minN = d[key]
		ans = key
print(ans)


from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations
from math import gcd, floor, inf
from bisect import bisect_right, bisect_left
num = int(input())
arr = list(map(int, input().split()))
ans = defaultdict(int)
for (i, n) in enumerate(arr):
	ans[n] = i
mn = inf
fnl = None
for (key, val) in ans.items():
	if val < mn:
		mn = val
		fnl = key
print(fnl)


def main():
	n = int(input())
	a = {}
	j = 0
	for i in list(map(int, input().split())):
		a[i] = j
		j += 1
	m = -1
	for i in a:
		if m == -1 or a[i] < a[m]:
			m = i
	return m
print(main())


n = int(input())
food = list(map(int, input().split()))
times = {}
for i in range(n):
	times[food[i]] = i
t = min(times.values())
print(food[t])


n = int(input())
vector = dict()
j = 1
for i in map(int, input().split()):
	vector[i] = j
	j += 1
m = min(vector.values())
for (i, j) in vector.items():
	if j == m:
		print(i)
		break


n = int(input())
numbers = [int(s) for s in input().split()]
new_numbers = []
els = set()
for el in numbers[::-1]:
	if el not in els:
		new_numbers.append(el)
		els.add(el)
print(new_numbers[-1])


n = int(input())
a = [int(i) for i in input().split()]
d = {}
for i in range(n):
	d[a[i]] = i
ans = 1000000
ans2 = 0
for i in d.keys():
	if d[i] < ans:
		ans2 = i
		ans = d[i]
print(ans2)


n = int(input())
x = list(map(int, input().split()))
a = 200001 * [10 ** 6]
for i in range(n):
	a[x[i]] = i + 1
print(a.index(min(a)))


n = int(input())
l = list(map(int, input().split()))
d = [0] * 200001
for i in range(n):
	d[l[i]] = n - i
print(d.index(max(d)))


n = int(input())
a = list(map(int, input().split()))
cafes = set(a)
output = 0
for i in range(1, n + 1):
	if a[-i] in cafes:
		cafes.remove(a[-i])
		output = a[-i]
print(output)


def ma():
	n = int(input())
	b = list(map(int, input().split()))
	k = {b[-1]}
	last = b[-1]
	for i in range(n - 1, -1, -1):
		if not b[i] in k:
			last = b[i]
			k.add(b[i])
	print(last)
ma()


n = int(input())
l = list(map(int, input().split()))
if n == 1:
	print(*l)
else:
	seet = set(l)
	for i in range(n - 1, -1, -1):
		if len(seet) == 1:
			break
		if l[i] in seet:
			seet.remove(l[i])
	for i in seet:
		print(i)


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


n = int(input())
a = list(map(int, input().split()))
d = {}
for (i, x) in enumerate(a):
	d[x] = i
print(min(d.items(), key=lambda x: x[1])[0])


n = int(input())
numbers = list(map(int, input().split()))
last = dict()
for i in set(numbers):
	last[i] = 0
for i in range(n):
	last[numbers[i]] = i
print(min(last.items(), key=lambda x: x[1])[0])


from sys import stdin as fin
n = int(fin.readline())
arr = list(map(int, fin.readline().split()))
s = dict()
for i in range(n):
	x = arr[i]
	s[x] = (i, x)
print(min(s.items(), key=lambda x: x[1])[0])


d = dict()
n = int(input())
nums = [int(x) for x in input().split()]
for i in range(n):
	d[nums[i]] = i
res = sorted(d.items(), key=lambda x: x[1])
print(res[0][0])


def main():
	read = lambda : tuple(map(int, input().split()))
	n = read()[0]
	l = read()
	last = {}
	for i in range(n):
		last[l[i]] = i
	mn = 10000000000.0
	ans = -1
	for k in last:
		if last[k] < mn:
			ans = k
			mn = last[k]
	print(ans)
main()


input()
X = list(map(int, input().split()))
MyDict = {}
for i in range(len(X)):
	MyDict[X[i]] = i
print(X[min(MyDict.values())])


t = int(input())
arr = list(map(int, input().split()))
finalindex = {}
j = 1
for i in reversed(arr):
	if i not in finalindex:
		finalindex[i] = j
		j += 1
print(max(finalindex, key=finalindex.get))


m = {}
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	m[a[i]] = i
ans = 0
k = 1000000.0
for i in set(a):
	if m[i] < k:
		k = m[i]
		ans = i
print(ans)


n = int(input())
dins = list(map(int, input().split()))
dd = dict()
for i in range(n):
	dd[dins[i]] = i
tmin = min(dd.values())
for el in dd:
	if dd[el] == tmin:
		print(el)
		break


n = int(input())
a = [int(x) for x in input().split()]
last = {}
alli = []
minim1 = 200001
minim2 = 200001
for i in range(n):
	if a[i] not in last:
		alli.append(a[i])
	last[a[i]] = i
for i in range(len(alli)):
	if last[alli[i]] < minim1:
		minim1 = last[alli[i]]
		minim2 = alli[i]
print(minim2)


n = int(input())
l = list(map(int, input().split()))
s = set()
ans = -1
for i in range(n - 1, -1, -1):
	if l[i] not in s:
		s.add(l[i])
		ans = l[i]
print(ans)


from collections import defaultdict
n = int(input())
a = [int(x) for x in input().split()]
d = defaultdict()
i = 1
for r in a:
	d[r] = i
	i += 1
l = list(d.items())
print(min(l, key=lambda r: r[1])[0])


n = int(input())
m = list(map(int, input().split(' ')))
m.reverse()
c = set(m)
d = dict.fromkeys(list(c), 0)
k = 0
a = len(c)
for i in m:
	if d[i] == 0:
		d[i] = 1
		k += 1
		if k == a:
			print(i)


n = int(input())
a = input().split()
m = set(a)
ans = a[n - 1]
for i in a[::-1]:
	if i in m and len(m) > 1:
		m.remove(i)
	if len(m) == 1:
		break
print(*m)


n = int(input())
masln = list(map(int, input().split()))
mal = {}
for i in range(n):
	mal[masln[i]] = i
minindex = 2147483647
ch = 0
for i in mal:
	if mal[i] < minindex:
		minindex = mal[i]
		ch = i
print(ch)


import sys
import math
import bisect
import itertools
import random
import re

def main():
	n = int(input())
	A = list(map(int, input().split()))
	d = dict()
	for i in range(n):
		d[A[i]] = i
	min_val = min(list(d.values()))
	for a in d:
		if d[a] == min_val:
			print(a)
			break
main()


n = int(input())
s = map(int, input().split())
d = {}
for (i, p) in enumerate(s):
	d[p] = i
min_i = min(d.values())
for s in d:
	if d[s] == min_i:
		print(s)
		break


n = int(input())
diningRooms = input().split()
diningRooms.reverse()
result = []
res_set = set()
for item in diningRooms:
	if item not in res_set:
		res_set.add(item)
		result.append(item)
print(result[len(result) - 1])


n = int(input())
s = [int(x) for x in input().split()]
Dict = {}
for i in range(n):
	if s[i] in Dict:
		Dict[s[i]] = i
	else:
		Dict.update({s[i]: i})
keys = list(Dict.keys())
min = (1, 10000000)
for i in range(len(Dict)):
	if Dict[keys[i]] < min[1]:
		min = (keys[i], Dict[keys[i]])
print(min[0])


n = int(input())
data = list(map(int, input().split()))
time = [-1 for i in range(2 * 10 ** 5 + 1)]
for i in range(n - 1, -1, -1):
	if time[data[i]] == -1:
		time[data[i]] = n - i - 1
max_time = -1
index = 0
for i in range(2 * 10 ** 5 + 1):
	if time[i] > max_time:
		max_time = time[i]
		index = i
print(index)


c = int(input())
a = list(map(int, input().split()))
b = []
for i in range(int(max(a)) + 1):
	b.append(0)
for i in range(len(a)):
	if b[int(a[len(a) - 1 - i])] == 0:
		b[int(a[len(a) - 1 - i])] = 1
		res = len(a) - 1 - i
print(a[res])


n = int(input())
l = list(map(int, input().split()))
a = [0 for i in range(200001)]
for i in range(n):
	a[l[i]] = i + 1
m = 1000000000
for i in range(200001):
	if a[i] != 0 and a[i] < m:
		mi = i
		m = a[i]
print(mi)


n = int(input())
last_num = list(map(int, input().split()))
queue = {}
for (i, num) in enumerate(last_num):
	queue[num] = i + 1
print(last_num[min(queue.values()) - 1])


n = int(input())
a = list(map(int, input().split(' ')))
d = {}
for i in range(n):
	d[a[i]] = i
min = n
min_k = -1
for k in d:
	if d[k] < min:
		min = d[k]
		min_k = k
print(min_k)


n = int(input())
s = input().split()
d = {}
for (i, el) in enumerate(s):
	d[el] = i
itg = sorted(list(d.items()), key=lambda x: int(x[1]))
print(itg[0][0])


import sys
input()
t = list(map(int, input().split()))
s = [2000000 for i in range(200001)]
for i in range(len(t)):
	s[t[i]] = i
mins = 2000001
mn = 0
for i in range(len(s)):
	if s[i] < mins:
		mins = s[i]
		mn = i
print(mn)


n = int(input())
a = input().split()
b = dict(((a[i], i) for i in range(n)))
print(a[min(b.values())])


n = int(input())
a = set()
res = 0
for i in list(map(int, input().split()))[::-1]:
	if i not in a:
		a.add(i)
		res = i
print(res)


from functools import reduce
n = int(input())
dic = {}
a = list(map(int, input().split()))
for i in range(n):
	dic[a[i]] = i
arr = []
for i in dic:
	arr.append((dic[i], i))
arr.sort()
print(arr[0][1])


n = int(input())
array = list(map(str, input().split()))
d = {}
for i in range(n):
	d[array[i]] = i
print(array[min([d[key] for key in d.keys()])])


n = int(input())
Dict = {}
a = [int(x) for x in input().split()]
for i in range(n):
	Dict[a[i]] = i + 1
mina = min(list(Dict.values()))
for (caf, ind) in Dict.items():
	if ind == mina:
		print(caf)
		break


n = int(input())
a = list(map(int, input().split()))
a = a[::-1]
s = set(a)
k = 0
for i in range(n):
	if len(s) == 1:
		print(s.pop())
		break
	if a[i] in s:
		s.remove(a[i])


n = int(input())
q = {}
t = {}
for (i, x) in enumerate(input().split()):
	y = int(x)
	t[i] = y
	if y in q:
		t.pop(q[y])
	q[y] = i
print(t[min(t)])


def main():
	n = int(input())
	arr = {}
	z = 0
	for i in list(map(int, input().split())):
		arr[i] = z
		z += 1
	ii = -1
	for i in arr:
		if ii == -1 or arr[i] < arr[ii]:
			ii = i
	return ii
print(main())


n = int(input())
a = [int(i) for i in input().split()]
cafe = {}
p = 0
for i in a:
	cafe[i] = p
	p += 1
min_val = min(cafe.values())
print([k for (k, v) in cafe.items() if v == min_val][0])


n = int(input())
l = list(map(int, input().split()))
l.reverse()
a = [0] * (max(l) + 1)
for (i, j) in enumerate(l):
	if a[j] == 0:
		a[j] = i + 1
print(a.index(max(a)))


n = int(input())
if n == 1:
	print(int(input()))
else:
	queue = {}
	last_num = list(map(int, input().split()))
	i = 0
	for num in last_num:
		i += 1
		queue[num] = i
	res = min(queue.values())
	print(last_num[res - 1])


n = int(input())
a = list(map(int, input().split()))
b = {}
for i in range(0, n):
	b[a[i]] = i
c = min(b.values())
print(a[c])


n = int(input())
A = [int(x) for x in input().split()]
last = [10 ** 6 for x in range(max(A) + 1)]
for i in range(0, n):
	last[A[i]] = i
print(A[min(last)])


n = int(input())
a = list(map(int, input().split()))
lastTime = dict()
rooms = set(a)
for i in range(n):
	lastTime[a[i]] = i
m = rooms.pop()
for room in rooms:
	if lastTime[room] < lastTime[m]:
		m = room
print(m)


a = int(input())
s = input().split()
q = set()
lenght = 0
for i in range(1, a + 1):
	q.add(s[i * -1])
	if len(q) > lenght:
		k = s[i * -1]
	lenght = len(q)
print(k)


n = int(input())
a = list(map(int, input().split()))
d = {}
for (i, k) in enumerate(a):
	d[k] = i
m = n + 1
r = 0
for (k, v) in d.items():
	if v < m:
		m = v
		r = k
print(r)


n = int(input())
a = list(reversed(list(map(int, input().split()))))
visited = set()
last = -1
for x in a:
	if x not in visited:
		visited.add(x)
		last = x
print(last)


n = int(input())
d = {}
a = [int(j) + 1 for j in input().split()]
for i in range(n):
	if a[i] != 0:
		d[a[i]] = i
mi = -1
for key in d:
	if mi == -1 or d[key] < d[mi]:
		mi = key
print(mi - 1)


count = int(input())
diary = list(map(int, input().split()))
oldest = diary[-1]
visited = set([oldest])
for record in reversed(diary[:-1]):
	if record not in visited:
		oldest = record
		visited.add(oldest)
print(oldest)


n = int(input())
spisok = list(map(int, input().split()))
d = {}
answer = 0
maximum = 0
for i in range(n):
	d[spisok[i]] = i
for (key, values) in d.items():
	if n - values >= maximum:
		answer = key
		maximum = n - values
print(answer)


import sys, math
from itertools import permutations
DEBUG = 0
if DEBUG:
	f = open('input.txt', 'r')
	input = f.readline
else:
	input = sys.stdin.readline

def mp():
	return list(map(int, input().split()))

def main():
	INF = int(1000000000.0)
	n = int(input())
	a = mp()
	last = [INF] * 200001
	for i in range(n):
		last[a[i]] = i
	print(last.index(min(last)))
main()


n = int(input())
a = list(map(int, input().split()))
v = [200000] * 200001
for (i, ai) in enumerate(a):
	v[ai] = i
print(a[min(v)])


n = int(input())
nums = [int(x) for x in input().split()]
d = dict()
for i in range(n):
	d[nums[i]] = i
ans = []
for (key, val) in d.items():
	ans.append([val, key])
ans.sort()
print(ans[0][1])


n = int(input())
a = list(map(int, input().split()))
a.reverse()
a_set = set()
for i in range(0, len(a)):
	if not a[i] in a_set:
		a_set.add(a[i])
		max_a = a[i]
print(max_a)


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
c = defaultdict(lambda : 0)
for i in range(len(a)):
	c[a[i]] = i
maxi = 0
k = len(a)
ne = 0
for key in c:
	if k - c[key] > maxi:
		ne = key
	maxi = max(maxi, k - c[key])
print(ne)


n = int(input())
x = list(map(int, input().split()))
last = []
for i in range(200002):
	last.append(n + 2)
for i in range(len(x)):
	last[x[i]] = i
curmin = n + 1
cur = 0
for i in range(200002):
	if last[i] < curmin:
		curmin = last[i]
		cur = i
print(cur)


n = int(input())
a = list(map(int, input().split()))
p = [-1] * 2 * 10 ** 6
s = 0
for i in range(n - 1, -1, -1):
	if p[a[i]] == -1:
		p[a[i]] = 1
		s = a[i]
print(s)


n = int(input())
a = [int(x) for x in input().split()]
b = [0] * 200001
ans = 0
for i in range(n - 1, -1, -1):
	if b[a[i]] == 0:
		b[a[i]] = 1
		ans = a[i]
print(ans)


ll = input()
rr = [int(i) for i in input().split()]
N = {}
c = 0
for i in rr:
	c += 1
	N[i] = c
print(sorted(N.items(), key=lambda x: x[1])[0][0])


def main():
	input()
	l = [999999] * 200001
	for (i, a) in enumerate(map(int, input().split())):
		l[a] = i
	print(min(range(200001), key=l.__getitem__))
main()


last_caffe = -1
cefes_count = int(input(''))
cafes_rating = input('').split(' ')
cafes_visited = {-1}
visited_cafes_count = 0
cafes_rating.reverse()
for x in cafes_rating:
	if not x in cafes_visited:
		cafes_visited.add(x)
		visited_cafes_count += 1
		last_caffe = x
	if visited_cafes_count == cefes_count:
		break
print(last_caffe)


n = int(input())
x = list(map(int, input().split(' ')))
bz = {}
for i in range(n):
	bz[x[i]] = i
print(x[min(bz.values())])


n = int(input())
a = list(map(int, input().split()))
m = 2 * 10 ** 5 + 1
last = [-1] * m
for i in range(n):
	last[a[i]] = i
cur_min = -1
for i in range(m):
	if last[i] != -1:
		if cur_min == -1 or last[i] < last[cur_min]:
			cur_min = i
print(cur_min)


n = int(input())
dist = [0] * (2 * 10 ** 5 + 1)
nums = [int(x) for x in input().split()]
for i in range(n - 1, -1, -1):
	if dist[nums[i]] == 0:
		dist[nums[i]] = n - i
mx = 0
for i in range(2 * 10 ** 5 + 1):
	if dist[i] > mx:
		mx = dist[i]
		ind = i
print(ind)


n = int(input())
mas = [int(i) for i in input().split()]
s = {}
for i in range(n):
	s[mas[i]] = i
g = sorted(s.keys(), key=lambda i: s[i])
print(g[0])


n = int(input())
canteenVisits = list(map(int, input().split()))
lastVisits = dict()
canteens = set(canteenVisits)
for i in range(n):
	lastVisits[canteenVisits[i]] = i
out = canteens.pop()
for canteen in canteens:
	if lastVisits[canteen] < lastVisits[out]:
		out = canteen
print(out)


n = int(input())
a = list(map(int, input().split(' ')))
m = {}
for i in range(n):
	m[a[i]] = i
w = -1
s = n
for key in m.keys():
	if m[key] < s:
		s = m[key]
		w = key
print(w)


size = int(input())
s = [int(i) for i in input().split(' ')]
stolovie = [0] * 1000
for i in range(size):
	try:
		stolovie[s[i]] = size - i
	except:
		stolovie = stolovie + [0] * s[i]
		stolovie[s[i]] = size - i
maxN = max(stolovie)
print(stolovie.index(maxN))


n = int(input())
l = list(map(int, input().split()))
m = n
lc = {}
for i in range(n):
	lc[l[i]] = i
for (key, value) in lc.items():
	if min(value, m) == value:
		r = key
		m = min(value, m)
print(r)


n = int(input())
a = list(map(int, input().split()))
times = [10 ** 9] * 10 ** 6
for i in range(n):
	times[a[i]] = i
print(times.index(min(times)))


n = int(input())
a = list(map(int, input().split()))
b = set()
i = a.__len__() - 1
c = 0
while i >= 0:
	if not a[i] in b:
		c = a[i]
		b.add(a[i])
	i -= 1
print(c)


def main():
	n = int(input())
	data = [int(v) for v in input().split()]
	last = {}
	for (i, v) in enumerate(data):
		last[v] = i
	r = sorted(last.items(), key=lambda b: b[1])
	print(r[0][0])
main()


n = int(input())
A = list(map(int, input().split()))
used = set()
cur = A[-1]
used.add(A[-1])
for i in range(n - 1, -1, -1):
	if A[i] not in used:
		cur = A[i]
		used.add(A[i])
print(cur)


n = int(input())
a = [int(i) for i in input().split()]
b = [2 * 10 ** 5] * (2 * 10 ** 5 + 1)
for i in range(n):
	b[a[i]] = i
print(b.index(min(b)))


n = input()
s = list(map(int, input().split()))
k = set()
g = len(s) - 1
for i in s:
	if i not in k:
		k.add(i)
i = -1
while len(k) != 1:
	k.discard(s[i])
	i -= 1
print(*k)


n = int(input())
nums = [int(j) for j in input().split()]
ref = 200001 * [0]
for j in range(n):
	ref[nums[j]] = n - j
(length, output) = (0, 0)
for j in range(200001):
	if length < ref[j]:
		(length, output) = (ref[j], j)
print(output)


from collections import deque
used = [0] * 1000000
a = deque()
n = int(input())
for i in input().split(' '):
	a.append(int(i))
	used[int(i)] += 1
i = a.popleft()
while used[i] != 1:
	used[i] -= 1
	i = a.popleft()
print(i)


n = int(input())
n -= 1
arr = list(map(int, input().split()))
rra = set(arr)
while n >= 0 and len(rra) > 1:
	rra.discard(arr[n])
	n -= 1
print(*rra)


n = int(input())
a = list(map(int, input().split()))
d = dict()
for i in range(len(a)):
	d[a[i]] = i
m = 300000
x = 0
for i in range(len(a)):
	if m > d[a[i]]:
		m = d[a[i]]
		x = i
print(a[x])


n = int(input())
a = [int(i) for i in input().split()]
b = [-1 for i in range(max(a) + 1)]
mpos = 10000000
for i in range(n):
	b[a[i]] = i
for i in range(len(b)):
	if b[i] != -1:
		if b[i] < mpos:
			mpos = b[i]
			ans = i
print(ans)


n = int(input())
a = list(map(int, input().split()))
a = list(reversed(a))
ai = list(set(a))
d = {x: -1 for x in ai}
for i in range(len(a)):
	if d[a[i]] == -1:
		d[a[i]] = i
z = list(d.keys())
x = list(d.values())
m = 0
for i in range(1, len(x)):
	if x[i] > x[m]:
		m = i
print(z[m])


import sys
MOD = 1000000007

def inp():
	return sys.stdin.readline().strip()

def ii():
	return int(inp())

def iis():
	return [int(i) for i in inp().split()]
n = ii()
print(list({el: 1 for el in iis()[::-1]}.keys())[-1])


n = int(input())
L = list(map(int, input().split()))
H = list(reversed(L))
d = {}
for i in set(L):
	d[i] = 30000005
for i in range(len(H)):
	d[H[i]] = min(d[H[i]], i)
K = list(d.keys())
V = list(d.values())
print(K[V.index(max(V))])


n = int(input())
a = list(map(int, input().split()))
seta = set(a)
setmet = set()
for i in range(n - 1, -1, -1):
	setmet.add(a[i])
	if setmet == seta:
		ans = a[i]
		break
print(ans)


n = int(input())
l = [int(el) for el in input().split()]
col = [-1] * 200001
for i in range(len(l)):
	col[l[i]] = i
min = 2000000
mincol = 0
for i in range(200001):
	if col[i] != -1 and col[i] < min:
		min = col[i]
		mincol = i
print(mincol)


n = int(input())
a = list(map(int, input().split()))
l = 2 * 10 ** 5 + 1
a1 = [-1] * l
for i in range(n):
	a1[a[i]] = i
max = 9999999999
imax = -99
for i in range(l):
	if a1[i] >= 0 and a1[i] < max:
		imax = i
		max = a1[i]
print(imax)


n = int(input())
m = [0 for _ in range(200001)]
for (i, v) in enumerate([int(k) for k in input().split(' ') if k]):
	m[v] = n - i
maxDistance = 0
result = 0
for i in range(len(m)):
	if 1 <= m[i] > maxDistance:
		result = i
		maxDistance = m[i]
print(result)


n = int(input())
a = list(map(int, input().split()))[:n]
s = set()
for i in a[::-1]:
	if i not in s:
		s.add(i)
		t = i
print(t)


n = int(input())
a = [int(i) for i in input().split()]
b = {}
for i in range(n):
	b[a[i]] = i
b = sorted(b.items(), key=lambda x: x[1])
print(b[0][0])


n = int(input())
a = list(map(int, input().split()))
a = a[::-1]
b = [0] * 200004
l = len(set(a))
j = 0
for i in a:
	if b[i] == 0 and j != l:
		b[i] = 1
		j += 1
	if j == l:
		print(i)
		exit(0)


def main():
	n = int(input())
	visits = list(map(int, input().split()))
	last = set()
	ans = 0
	for i in range(1, n + 1):
		if visits[-i] not in last:
			ans = visits[-i]
			last.add(visits[-i])
	print(ans)
main()


n = int(input())
arr = list(map(int, input().split()))
seen = set()
ans = 0
for i in range(n - 1, -1, -1):
	if arr[i] in seen:
		pass
	else:
		ans = arr[i]
		seen.add(arr[i])
print(ans)


def main():
	n = int(input())
	b = set()
	a = list(map(int, input().split()))
	k = a[n - 1]
	b.add(k)
	for i in range(1, n):
		if not a[n - i - 1] in b:
			b.add(k)
			k = a[n - i - 1]
			b.add(k)
	print(k)
main()


n = int(input())
a = list(map(int, input().split()))
b = set(a)
for i in range(1, n + 1):
	if a[-i] in b:
		b.remove(a[-i])
		ans = a[-i]
print(ans)


n = int(input())
a = list(map(int, input().split(' ')))
vis = [False] * (max(a) + 1)
ans = list()
for i in range(len(a) - 1, -1, -1):
	if not vis[a[i]]:
		ans.append(a[i])
		vis[a[i]] = True
print(ans[len(ans) - 1])


m = input()
a = list(map(int, input().split()))
a.reverse()
dic = {}
i = 0
for m in a:
	if m not in dic:
		dic[m] = i
		i += 1
print(max(dic, key=dic.get))


n = int(input())
mas = list(map(int, input().split()))
s = dict()
for (i, e) in enumerate(mas):
	s[e] = i
print(mas[min(s.values())])


n = int(input())
ar = list(reversed(input().split()))
a = len(ar) - len(set(ar))
d = dict()
k = 1
for i in ar:
	if i not in d.keys():
		d[i] = k
	k += 1
m = 0
for (i, j) in d.items():
	if j >= m:
		ans = i
		m = j
print(ans)