You've got an undirected graph, consisting of n vertices and m edges. We will consider the graph's vertices numbered with integers from 1 to n. Each vertex of the graph has a color. The color of the i-th vertex is an integer c_{i}.

Let's consider all vertices of the graph, that are painted some color k. Let's denote a set of such as V(k). Let's denote the value of the neighbouring color diversity for color k as the cardinality of the set Q(k) = {c_{u} :  c_{u} ≠ k and there is vertex v belonging to set V(k) such that nodes v and u are connected by an edge of the graph}.

Your task is to find such color k, which makes the cardinality of set Q(k) maximum. In other words, you want to find the color that has the most diverse neighbours. Please note, that you want to find such color k, that the graph has at least one vertex with such color.


-----Input-----

The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 10^5) — the number of vertices end edges of the graph, correspondingly. The second line contains a sequence of integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^5) — the colors of the graph vertices. The numbers on the line are separated by spaces.

Next m lines contain the description of the edges: the i-th line contains two space-separated integers a_{i}, b_{i} (1 ≤ a_{i}, b_{i} ≤ n; a_{i} ≠ b_{i}) — the numbers of the vertices, connected by the i-th edge. 

It is guaranteed that the given graph has no self-loops or multiple edges.


-----Output-----

Print the number of the color which has the set of neighbours with the maximum cardinality. It there are multiple optimal colors, print the color with the minimum number. Please note, that you want to find such color, that the graph has at least one vertex with such color.


-----Examples-----
Input
6 6
1 1 2 3 5 8
1 2
3 2
1 4
4 3
4 5
4 6

Output
3

Input
5 6
4 2 5 2 4
1 2
2 3
3 1
5 3
5 4
3 4

Output
2

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Graph algorithms

Graph traversal

Complete search


Solutions:
from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
from math import *
from collections import defaultdict as dd, deque

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

def mdata():
	return map(int, data().split())
sys.setrecursionlimit(100000)
(n, m) = mdata()
C = list(mdata())
g = dd(set)
d = dd(set)
for i in range(m):
	(a, b) = mdata()
	c1 = C[a - 1]
	c2 = C[b - 1]
	if c1 != c2:
		d[c1].add(c2)
		d[c2].add(c1)
m = 0
ind = min(C)
for i in sorted(d.keys()):
	if len(d[i]) > m:
		m = len(d[i])
		ind = i
print(ind)


(n, m) = map(int, input().split())
c = list(map(int, input().split()))
M = max(c)
g = [set() for _ in range(M + 1)]
for _ in range(m):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	if c[a] != c[b]:
		g[c[a]].add(c[b])
		g[c[b]].add(c[a])
ans = min(c)
for i in range(M + 1):
	if len(g[i]) > len(g[ans]):
		ans = i
print(ans)


__autor__ = 'Esfandiar'
import sys
input = sys.stdin.readline
from collections import defaultdict
(n, m) = list(map(int, input().split()))
c = list(map(int, input().split()))
g = [[] for _ in range(n)]
for i in range(m):
	(u, v) = list(map(int, input().split()))
	g[u - 1].append(v - 1)
	g[v - 1].append(u - 1)
color = defaultdict(list)
for u in range(n):
	color[c[u]].append(u)
M = -float('inf')
for k in list(color.keys()):
	seen = dict()
	res = 0
	for v in color[k]:
		for u in g[v]:
			if c[u] != k and seen.get(c[u], -1) == -1:
				res += 1
				seen[c[u]] = 1
		if res > M:
			M = res
			kk = k
		elif res == M:
			kk = min(kk, k)
print(kk)


(n, m) = list(map(int, input().strip().split()))
color = list(map(int, input().strip().split()))
g = [[] for i in range(n)]
colors = {i: set() for i in sorted(color)}
for i in range(m):
	(x, y) = list(map(int, input().strip().split()))
	x -= 1
	y -= 1
	if color[x] != color[y]:
		colors[color[x]].add(color[y])
		colors[color[y]].add(color[x])
print(max(colors, key=lambda _: len(colors[_])))


(n, m) = map(int, input().split())
color = list(map(int, input().split()))
x = list(zip(*[list(map(int, input().split())) for i in range(m)]))
y = x[1]
x = x[0]
ans = dict()
for i in color:
	if i not in ans:
		ans[i] = set()
for i in range(m):
	if color[x[i] - 1] != color[y[i] - 1]:
		ans[color[x[i] - 1]].add(color[y[i] - 1])
		ans[color[y[i] - 1]].add(color[x[i] - 1])
for i in ans:
	Max = i
	break
MaxLen = len(ans[Max])
for i in ans:
	LAns = len(ans[i])
	if MaxLen < LAns or (MaxLen == LAns and Max > i):
		Max = i
		MaxLen = LAns
print(Max)


from collections import defaultdict
from sys import stdin
input = stdin.readline

class N:

	def __init__(self, c) -> None:
		self.c = c
		self.ch = []

def __starting_point():
	(n, m) = list(map(int, input().split()))
	carr = list(map(int, input().split()))
	arr = [N(x) for x in carr]
	for _ in range(m):
		(a, b) = list(map(int, input().split()))
		arr[a - 1].ch.append(arr[b - 1])
		arr[b - 1].ch.append(arr[a - 1])
	for x in arr:
		x.ch = list([y for y in x.ch if y.c != x.c])
	dct = defaultdict(lambda : set())
	for x in arr:
		for y in x.ch:
			if y.c != x.c:
				dct[x.c].add(y.c)
	narr = []
	for (key, value) in list(dct.items()):
		narr.append((key, len(value)))
	narr.sort(key=lambda x: x[1], reverse=True)
	if narr:
		narr = list(sorted([x for x in narr if x[1] == narr[0][1]], key=lambda x: x[0]))
		print(narr[0][0])
	else:
		print(min(carr))
__starting_point()


import sys
input = sys.stdin.readline
from collections import *
(n, m) = map(int, input().split())
c = list(map(int, input().split()))
d = defaultdict(list)
for i in range(n):
	d[c[i]].append(i)
G = [[] for _ in range(n)]
for _ in range(m):
	(a, b) = map(int, input().split())
	G[a - 1].append(b - 1)
	G[b - 1].append(a - 1)
M = -1
for k in sorted(d.keys()):
	s = set()
	for v in d[k]:
		for nv in G[v]:
			if c[nv] != k:
				s.add(c[nv])
	if len(s) > M:
		M = len(s)
		ans = k
print(ans)


def parser():
	return [int(x) for x in input().split()]
(n, m) = parser()
colors_vertices = parser()
upper = max(colors_vertices)
adjacents_sets = [set() for x in range(upper)]
for i in range(m):
	edge = parser()
	color1 = colors_vertices[edge[0] - 1]
	color2 = colors_vertices[edge[1] - 1]
	if color1 != color2:
		adjacents_sets[color1 - 1].add(color2)
		adjacents_sets[color2 - 1].add(color1)
max_neighbours = 0
color = 0
for i in range(upper):
	if max_neighbours < len(adjacents_sets[i]):
		max_neighbours = len(adjacents_sets[i])
		color = i + 1
if max_neighbours == 0:
	print(min(colors_vertices))
else:
	print(color)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	(n, m) = sep()
	c = lis()
	g = [[] for i in range(n)]
	for i in range(m):
		(a, b) = sep()
		a -= 1
		b -= 1
		g[a].append(b)
		g[b].append(a)
	cnt = [{-1} for i in range(100005)]
	for i in range(n):
		for j in g[i]:
			if c[j] != c[i]:
				cnt[c[i]].add(c[j])
	ans = -1
	col = 0
	have = list(set(c))
	have = sorted(have)
	for i in have:
		if len(cnt[i]) == 1:
			continue
		if len(cnt[i]) - 1 > ans:
			col = i
			ans = len(cnt[i]) - 1
	if ans == -1:
		col = min(c)
	print(col)
testcase(1)


(n, m) = list(map(int, input().split()))
l = list(map(int, input().split()))
d = {x: set() for x in set(l)}
for i in range(m):
	(a, b) = list(map(int, input().split()))
	if l[a - 1] != l[b - 1]:
		d[l[a - 1]].add(l[b - 1])
		d[l[b - 1]].add(l[a - 1])
d = sorted(d, key=lambda x: (len(d[x]), -x))
print(d[-1])


import sys
(v, e) = input().split()
v = int(v)
e = int(e)
adj = {}
color = [int(x) for x in input().split()]
for c in color:
	adj[c] = set()
color.insert(0, 0)
for i in range(e):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if color[a] != color[b]:
		adj[color[a]].add(color[b])
		adj[color[b]].add(color[a])
min_color = sys.maxsize
max_div = 0
for key in adj.keys():
	if len(adj[key]) > max_div:
		min_color = key
		max_div = len(adj[key])
	elif len(adj[key]) == max_div:
		if key < min_color:
			min_color = key
print(min_color)


from sys import stdin

def main():
	(n, m) = map(int, input().split())
	cc = [0, *map(int, input().split())]
	(d, f) = ({c: set() for c in cc}, cc.__getitem__)
	for s in stdin.read().splitlines():
		(u, v) = map(f, map(int, s.split()))
		d[u].add(v)
		d[v].add(u)
	print(max(cc[1:], key=lambda c: (len(d[c]) - (c in d[c]), -c)))
main()


from collections import defaultdict
l = lambda : map(int, input().split())
(n, m) = l()
c = list(l())
graph = defaultdict(set)
for i in range(m):
	(a, b) = l()
	if c[a - 1] == c[b - 1]:
		continue
	graph[c[a - 1]].add(c[b - 1])
	graph[c[b - 1]].add(c[a - 1])
(d, f) = (min(c), 0)
for i in sorted(graph):
	h = len(graph[i])
	if h > f:
		f = h
		d = i
print(d)


from collections import defaultdict
(n, m) = map(int, input().split())
colour = [0] + list(map(int, input().split()))
(mx, ans) = (0, min(colour[1:]))
count = defaultdict(set)
for _ in range(m):
	(a, b) = map(int, input().split())
	if colour[a] != colour[b]:
		count[colour[a]].add(colour[b])
		count[colour[b]].add(colour[a])
for colour in count:
	if len(count[colour]) > mx:
		mx = len(count[colour])
		ans = colour
	elif len(count[colour]) == mx and colour < ans:
		ans = colour
print(ans)


(n, m) = map(int, input().split())
cs = [0] + list(map(int, input().split()))
g = [set() for _ in range(10 ** 5 + 5)]
for _ in range(m):
	(u, v) = map(int, input().split())
	if cs[u] != cs[v]:
		g[cs[u]].add(cs[v])
		g[cs[v]].add(cs[u])
ans = min(cs[1:])
for i in range(1, 10 ** 5 + 5):
	if len(g[i]) > len(g[ans]):
		ans = i
print(ans)


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
a.insert(0, -1)
g = [[] for i in range(n + 1)]
for i in range(m):
	(u, v) = list(map(int, input().split()))
	g[u].append(v)
	g[v].append(u)
div = [0]
for i in range(1, n + 1):
	s = set()
	for j in g[i]:
		if a[j] != a[i]:
			s.add(a[j])
	div.append(s)
c = {}
for i in range(1, len(a)):
	if a[i] in c:
		c[a[i]].append(i)
	else:
		c[a[i]] = [i]
m = 0
ind = 1000000
for i in c:
	d = set()
	for j in c[i]:
		for k in div[j]:
			d.add(k)
	if len(d) > m:
		ind = i
		m = len(d)
	elif len(d) == m:
		ind = min(ind, i)
print(ind)


from collections import deque
MAX_COLORS = 10

def bfs(vertex):
	global adjlist, visited, colors, dvt, count, idx
	queue = deque()
	queue.append(vertex)
	visited[vertex] = 1
	while queue:
		curv = queue.popleft()
		for v in adjlist[curv]:
			if colors[v] != colors[curv]:
				if colors[curv] not in dvt:
					dvt[colors[curv]] = {colors[v]}
				else:
					dvt[colors[curv]].add(colors[v])
				if len(dvt[colors[curv]]) > count:
					idx = colors[curv]
					count = len(dvt[colors[curv]])
				elif len(dvt[colors[curv]]) == count and colors[curv] < idx:
					idx = colors[curv]
			if visited[v] == 0:
				queue.append(v)
				visited[v] = 1
(n, m) = [int(x) for x in input().split()]
colors = []
adjlist = [[] for x in range(n)]
dvt = {}
visited = [0] * n
colors = [int(x) for x in input().split()]
for i in range(m):
	(x, y) = [int(x) for x in input().split()]
	x -= 1
	y -= 1
	adjlist[x].append(y)
	adjlist[y].append(x)
count = 0
idx = min(colors)
for i in range(n):
	if visited[i] == 0:
		bfs(i)
print(idx)


from sys import stdin
input = stdin.readline
(n, m) = map(int, input().split())
c = list(map(int, input().split()))
g = [[] for i in range(n)]
g_color = [set() for i in range(n)]
for _ in range(m):
	(u, v) = map(int, input().split())
	g[u - 1].append(v - 1)
	g[v - 1].append(u - 1)
	g_color[u - 1].add(c[v - 1])
	g_color[v - 1].add(c[u - 1])
q = [set() for i in range(10 ** 5 + 1)]
for i in range(n):
	q[c[i]] = q[c[i]] | g_color[i]
ans = -1
M = -1
cc = sorted(list(set(c)))
for j in range(len(cc)):
	i = cc[j]
	val = len(list(q[i]))
	if i in q[i]:
		val -= 1
	if M < val:
		ans = i
		M = val
print(ans)


import os, sys, math
from io import BytesIO, IOBase
from collections import defaultdict, deque, OrderedDict
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(input())

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

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

def Sn():
	return input().strip()
BUFSIZE = 8192

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return len(a)

def solve():
	(n, m) = In()
	cost = list(In())
	cp = defaultdict(list)
	for i in range(n):
		cp[cost[i]].append(i)
	gp = defaultdict(list)
	for i in range(m):
		(a, b) = list(In())
		(a, b) = (a - 1, b - 1)
		gp[a].append(b)
		gp[b].append(a)
	cnt = 0
	ans1 = float('inf')
	for x in cp:
		st = cp[x]
		ans = set()
		for y in st:
			for v in gp[y]:
				if cost[v] != cost[y]:
					ans.add(cost[v])
		if len(ans) == cnt:
			ans1 = min(ans1, x)
		elif len(ans) > cnt:
			cnt = len(ans)
			ans1 = x
	print(ans1)
	pass

def main():
	T = 1
	for i in range(T):
		solve()
M = 998244353
P = 1000000007

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = list(map(int, input().split()))
c = list(map(int, input().split()))
a = [[] for i in range(100000)]
b = [0] * 100000
for i in range(m):
	d = list(map(int, input().split()))
	if c[d[1] - 1] != c[d[0] - 1]:
		a[c[d[0] - 1] - 1].append(c[d[1] - 1])
		a[c[d[1] - 1] - 1].append(c[d[0] - 1])
for i in range(100000):
	a[i].sort()
	if a[i] != []:
		b[i] += 1
		for j in range(len(a[i]) - 1):
			if a[i][j] != a[i][j + 1]:
				b[i] += 1
d = c[0] - 1
for i in c:
	if b[i - 1] > b[d] or (b[i - 1] == b[d] and i - 1 < d):
		d = i - 1
print(d + 1)


from sys import stdin
from collections import *

def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return list(stdin.readline()[:-1])

def main():
	(n, m) = arr_inp(1)
	(c, ans, ma) = (arr_inp(1), float('inf'), 0)
	mem = defaultdict(set)
	for i in range(m):
		(u, v) = arr_inp(1)
		u -= 1
		v -= 1
		if c[u] != c[v]:
			mem[c[u]].add(c[v])
			mem[c[v]].add(c[u])
	for (i, j) in list(mem.items()):
		if len(j) > ma:
			ma = max(ma, len(j))
			ans = i
		if len(j) == ma:
			ans = min(ans, i)
	print(ans if ans != float('inf') else min(c))

def __starting_point():
	main()
__starting_point()


import sys
input = sys.stdin.readline
from collections import defaultdict

def dfs(i):
	st = [i]
	while st:
		x = st.pop()
		if vis[x]:
			continue
		vis[x] = 1
		for v in sorted(g[x]):
			if c[x - 1] != c[v - 1]:
				d[c[x - 1]].add(c[v - 1])
			if not vis[v]:
				st.append(v)
(n, m) = map(int, input().split())
c = list(map(int, input().split()))
g = [[] for i in range(n + 1)]
for i in range(m):
	(x, y) = map(int, input().split())
	g[x].append(y)
	g[y].append(x)
d = defaultdict(set)
vis = [0] * (n + 1)
for i in range(1, n + 1):
	if vis[i] == 0:
		dfs(i)
k = sorted(d.keys(), key=lambda i: (len(d[i]), -i))
if not k:
	print(min(c))
else:
	print(k[-1])


(n, m) = map(int, input().split())
c = [0] + list(map(int, input().split()))
t = {i: [] for i in set(c[1:])}
for i in range(m):
	(a, b) = map(int, input().split())
	if c[a] != c[b]:
		t[c[a]].append(c[b])
		t[c[b]].append(c[a])
(j, k) = (c[1], 0)
for (i, s) in t.items():
	l = len(set(s))
	if l >= k:
		if l > k:
			(j, k) = (i, l)
		elif j > i:
			j = i
print(j)


from collections import defaultdict
(n, m) = map(int, input().split())
c = list(map(int, input().split()))
res = defaultdict(set)
for _ in range(m):
	(u, v) = map(lambda x: int(x) - 1, input().split())
	if c[u] != c[v]:
		res[c[u]].add(c[v])
		res[c[v]].add(c[u])
res_count = -1
res_color = -1
for color in c:
	count = res[color]
	if res_count == -1 or res_count < len(count):
		res_count = len(count)
		res_color = color
	elif res_count == len(count) and color < res_color:
		res_color = color
print(res_color)


(n, m) = map(int, input().split())
col = list(map(int, input().split()))
cs = set(col)
cnt = [None] * 100001
for i in range(100001):
	cnt[i] = set()
for i in range(m):
	(u, v) = map(int, input().split())
	if col[u - 1] != col[v - 1]:
		cnt[col[u - 1]].add(col[v - 1])
		cnt[col[v - 1]].add(col[u - 1])
ans = -1
mx = -1
for i in range(100001):
	if mx < len(cnt[i]) and i in cs:
		mx = len(cnt[i])
		ans = i
print(ans)


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
ans = {}
for i in l:
	ans[i] = set()
for i in range(m):
	(a, b) = map(int, input().split())
	if l[a - 1] != l[b - 1]:
		ans[l[a - 1]].add(l[b - 1])
		ans[l[b - 1]].add(l[a - 1])
ma = 0
t = float('infinity')
for i in ans:
	if len(ans[i]) >= ma:
		ma = len(ans[i])
for i in ans:
	if len(ans[i]) == ma:
		t = min(t, i)
print(t)


from collections import defaultdict
get = lambda : map(int, input().split())
(n, m) = get()
c = list(get())
adj = {i: set() for i in sorted(c)}
for i in range(m):
	(a, b) = get()
	if c[a - 1] != c[b - 1]:
		adj[c[b - 1]].add(c[a - 1])
		adj[c[a - 1]].add(c[b - 1])
print(max(adj, key=lambda x: len(adj[x])))


I = lambda : list(map(int, input().split()))
import collections as cc
g = cc.defaultdict(list)
(n, m) = I()
c = I()
f = cc.defaultdict(set)
for i in set(c):
	f[i].add(i)
for i in range(m):
	(x, y) = I()
	if c[y - 1] not in f[c[x - 1]]:
		f[c[x - 1]].add(c[y - 1])
	if c[x - 1] not in f[c[y - 1]]:
		f[c[y - 1]].add(c[x - 1])
mx = max(f, key=lambda x: len(f[x]))
ans = 10 ** 9 + 7
mm = len(f[mx])
for i in f:
	if len(f[i]) == mm:
		ans = min(ans, i)
print(ans)


def parser():
	return [int(x) for x in input().split(' ')]
(n, m) = parser()
colors_vertices = parser()
colors = set(colors_vertices)
color_pos = {}
pos_color = {}
sets = [set() for x in colors]
i = 0
for color in colors:
	color_pos[color] = i
	pos_color[i] = color
	i += 1
for i in range(m):
	edge = parser()
	color1 = colors_vertices[edge[0] - 1]
	color2 = colors_vertices[edge[1] - 1]
	if color1 != color2:
		sets[color_pos[color1]].add(color2)
		sets[color_pos[color2]].add(color1)
max = 0
result = -1
for color in color_pos:
	if max < len(sets[color_pos[color]]):
		max = len(sets[color_pos[color]])
		result = color
	if max == len(sets[color_pos[color]]) and color < result:
		result = color
if max == 0:
	print(min(colors))
else:
	print(result)


from __future__ import print_function
from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n, m) = gil()
c = [0] + gil()
adj = [[] for _ in range(n + 1)]
for _ in range(m):
	(x, y) = gil()
	adj[x].append(y)
	adj[y].append(x)
maxC = int(100000.0)
s = [set() for i in range(maxC + 1)]
for p in range(1, n + 1):
	s[c[p]].add(c[p])
	for ch in adj[p]:
		s[c[p]].add(c[ch])
print(max(range(1, maxC + 1), key=lambda x: len(s[x])))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import heapq
import math
from collections import Counter
from bisect import bisect_right
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
d = {x: set() for x in arr}
for i in range(k):
	(u, v) = map(int, input().split())
	if arr[u - 1] != arr[v - 1]:
		d[arr[u - 1]].add(arr[v - 1])
		d[arr[v - 1]].add(arr[u - 1])
d = sorted(d, key=lambda x: (len(d[x]), -x))
print(d[-1])


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, m) = map(int, input().split())
	c = [-1] + list(map(int, input().split()))
	k = max(c) + 1
	color = [set() for _ in range(k)]
	for _ in range(m):
		(a, b) = map(int, input().split())
		(a, b) = (c[a], c[b])
		if a != b:
			color[a].add(b)
			color[b].add(a)
	mx = 0
	ans = -1
	for i in range(1, k):
		t = len(color[i])
		if t > mx:
			mx = t
			ans = i
	if ans == -1:
		ans = min(c[1:])
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
gr = [set() for i in range(n)]
for i in range(m):
	(u, v) = map(int, input().split())
	gr[u - 1].add(v - 1)
	gr[v - 1].add(u - 1)
tr = {}
for i in range(max(a)):
	tr[i] = set()
for i in range(n):
	b = a[i]
	for j in gr[i]:
		if a[j] != b:
			tr[b - 1].add(a[j] - 1)
ans = 0
pos = min(a)
for i in range(max(a)):
	if len(tr[i]) > ans:
		ans = len(tr[i])
		pos = i + 1
print(pos)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections as col
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7
import bisect

def solve():
	(N, M) = getInts()
	Q = col.defaultdict(set)
	colours = getInts()
	for colour in colours:
		Q[colour] = set()
	for m in range(M):
		(A, B) = getInts()
		if colours[A - 1] != colours[B - 1]:
			Q[colours[A - 1]].add(colours[B - 1])
			Q[colours[B - 1]].add(colours[A - 1])
	best = 0
	best_col = 10 ** 9 + 1
	for (key, val) in Q.items():
		if len(val) > best:
			best = len(val)
			best_col = key
		elif len(val) == best:
			best_col = min(best_col, key)
	return best_col
print(solve())


import sys
input = sys.stdin.readline
from collections import defaultdict, deque

class Graph:

	def __init__(self, N, Color):
		self.vertices = N
		self.Color = Color
		self.graph = defaultdict(set)

	def addEdge(self, fr, to):
		if self.Color[to - 1] != self.Color[fr - 1]:
			self.graph[Color[fr - 1]].add(self.Color[to - 1])
			self.graph[Color[to - 1]].add(self.Color[fr - 1])

	def solver(self):
		Ans = -1
		NodeColor = 0
		for i in self.Color:
			if len(self.graph[i]) == Ans:
				NodeColor = min(i, NodeColor)
			elif len(self.graph[i]) > Ans:
				Ans = len(self.graph[i])
				NodeColor = i
		return NodeColor
(N, M) = map(int, input().split())
Color = [int(x) for x in input().split()]
G = Graph(N, Color)
for i in range(M):
	(fr, to) = map(int, input().split())
	G.addEdge(fr, to)
print(G.solver())


from collections import defaultdict
(n, m) = map(int, input().split())
g = defaultdict(set)
c = list(map(int, input().split()))
for _ in range(m):
	(x, y) = map(int, input().split())
	if c[x - 1] != c[y - 1]:
		g[c[x - 1]].add(c[y - 1])
	if c[y - 1] != c[x - 1]:
		g[c[y - 1]].add(c[x - 1])
ma = 0
co = 10 ** 5 + 1
f = 0
for i in g:
	ma = max(ma, len(g[i]))
for i in g:
	if len(g[i]) == ma:
		f += 1
		co = min(co, i)
if f == 0:
	co = min(c)
print(co)


import math
import bisect
import itertools
import sys
I = lambda : sys.stdin.readline()
one = lambda : int(I())
more = lambda : map(int, I().split())
linput = lambda : list(more())
mod = 10 ** 9 + 7
inf = 10 ** 18 + 1

def merge(a, b):
	i = 0
	j = 0
	c = 0
	ans = []
	while i < len(a) and j < len(b):
		if a[i] < b[j]:
			ans.append(a[i])
			i += 1
		else:
			ans.append(b[j])
			c += len(a) - i
			j += 1
	ans += a[i:]
	ans += b[j:]
	return (ans, c)

def mergesort(a):
	if len(a) == 1:
		return (a, 0)
	mid = len(a) // 2
	(left, left_inversion) = mergesort(a[:mid])
	(right, right_inversion) = mergesort(a[mid:])
	(m, c) = merge(left, right)
	c += left_inversion + right_inversion
	return (m, c)

def is_prime(num):
	if num == 1:
		return False
	if num == 2:
		return True
	if num == 3:
		return True
	if num % 2 == 0:
		return False
	if num % 3 == 0:
		return False
	t = 5
	a = 2
	while t <= int(math.sqrt(num)):
		if num % t == 0:
			return False
		t += a
		a = 6 - a
	return True

def ceil(a, b):
	return (a + b - 1) // b
(n, m) = more()
color = [0] + linput()
nn = max(color)
a = [set() for i in range(nn + 1)]
for i in range(m):
	(x, y) = more()
	if color[x] != color[y]:
		a[color[x]].add(color[y])
		a[color[y]].add(color[x])
ans = 0
col = 10 ** 12
for i in range(1, nn + 1):
	if ans < len(a[i]):
		col = i
		ans = max(ans, len(a[i]))
	elif ans == len(a[i]):
		col = min(i, col)
if ans == 0:
	print(min(color[1:]))
else:
	print(col)


def parser():
	return [int(x) for x in input().split()]
(n, m) = parser()
colors_vertices = parser()
colors = set(colors_vertices)
adjacents_sets = [set() for x in colors]
color_pos = {}
i = 0
for color in colors:
	color_pos[color] = i
	i += 1
for i in range(m):
	edge = parser()
	color1 = colors_vertices[edge[0] - 1]
	color2 = colors_vertices[edge[1] - 1]
	if color1 != color2:
		adjacents_sets[color_pos[color1]].add(color2)
		adjacents_sets[color_pos[color2]].add(color1)
max_neighbours = -1
result = -1
for color in color_pos:
	if max_neighbours < len(adjacents_sets[color_pos[color]]):
		max_neighbours = len(adjacents_sets[color_pos[color]])
		result = color
	if max_neighbours == len(adjacents_sets[color_pos[color]]) and color < result:
		result = color
print(result)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
(n, m) = list(map(int, input().split()))
color = list(map(int, input().split()))
graph = [[] for i in range(n)]
mpper = defaultdict(set)
for i in range(m):
	(u, v) = list(map(int, input().split()))
	u -= 1
	v -= 1
	graph[u].append(v)
	graph[v].append(u)
	if color[u] != color[v]:
		mpper[color[u]].add(color[v])
		mpper[color[v]].add(color[u])
freq = defaultdict(int)
for i in range(n):
	freq[color[i]] = len(mpper[color[i]])
ind = -1
ans = -1
for i in freq:
	if ans < freq[i]:
		ans = max(ans, freq[i])
		ind = i
	if freq[i] == ans:
		ind = min(ind, i)
print(ind)


import bisect
import math
from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
ii = lambda : int(input())
lmii = lambda : list(map(int, input().split()))
slmii = lambda : sorted(map(int, input().split()))
li = lambda : list(input())
mii = lambda : map(int, input().split())
msi = lambda : map(str, input().split())

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def main():
	(n, m) = mii()
	c = lmii()
	adj = defaultdict(list)
	s = defaultdict(set)
	for i in c:
		if s[i]:
			pass
	for i in range(m):
		(a, b) = mii()
		if c[a - 1] != c[b - 1]:
			s[c[a - 1]].add(c[b - 1])
			s[c[b - 1]].add(c[a - 1])
	mx = -1
	ans = -1
	for i in s:
		ln = len(s[i])
		if ln > mx:
			ans = i
			mx = ln
		if ln == mx:
			ans = min(ans, i)
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi, ceil, log, inf
from itertools import permutations
from copy import deepcopy
from heapq import *
from sys import setrecursionlimit

def main():
	(n, m) = map(int, input().split())
	c = list(map(int, input().split()))
	tree = defaultdict(set)
	for i in range(m):
		(x, y) = map(int, input().split())
		if c[x - 1] != c[y - 1]:
			tree[c[x - 1]].add(c[y - 1])
			tree[c[y - 1]].add(c[x - 1])
	if len(tree) != 0:
		print(max(tree, key=lambda z: len(tree[z]) * 1000000 - z))
	else:
		print(min(c))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = map(int, input().split())
c = list(map(int, input().split()))
d = {}
for i in range(m):
	(x, y) = map(int, input().split())
	if x not in d:
		d[x] = []
	if y not in d:
		d[y] = []
	d[x].append(y)
	d[y].append(x)
for i in range(1, n + 1):
	if i not in d:
		d[i] = []
color = {}
for i in range(n):
	if c[i] not in color:
		color[c[i]] = set()
	color[c[i]].add(i + 1)
fq = {}
for i in color:
	fq[i] = set()
for i in color:
	for j in color[i]:
		for k in d[j]:
			if c[k - 1] != i:
				fq[i].add(c[k - 1])
mx = -1
for i in fq:
	if len(fq[i]) > mx:
		mx = len(fq[i])
		ans = i
	elif len(fq[i]) == mx:
		ans = min(ans, i)
print(ans)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
(colours, best, best_car) = ([int(i) for i in input().split()], float('inf'), 0)
colours_set = set(colours)
colours_graph = {colour: set() for colour in colours_set}
for i in range(m):
	(a, b) = map(int, input().split())
	if colours[a - 1] in colours_set and colours[b - 1] in colours_set and (colours[a - 1] != colours[b - 1]):
		colours_graph[colours[a - 1]].add(colours[b - 1])
		colours_graph[colours[b - 1]].add(colours[a - 1])
for colour in colours_graph:
	if len(colours_graph[colour]) > best_car or (len(colours_graph[colour]) == best_car and colour < best):
		best = colour
		best_car = len(colours_graph[colour])
print(best)


from collections import defaultdict
(n, m) = map(int, input().split())
colors = list(map(int, input().split()))
d1 = {}
d2 = defaultdict(set)
for i in range(n):
	d1[i + 1] = []
for i in range(m):
	(a, b) = map(int, input().split())
	d1[a].append(b)
	d1[b].append(a)
	if colors[b - 1] != colors[a - 1]:
		d2[colors[a - 1]].add(colors[b - 1])
	if colors[a - 1] != colors[b - 1]:
		d2[colors[b - 1]].add(colors[a - 1])
maxi = 0
ans = min(colors)
for i in sorted(d2.keys()):
	if maxi < len(d2[i]):
		ans = i
		maxi = len(d2[i])
print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass

def pmat(A):
	for ele in A:
		print(*ele, end='\n')
(n, m) = L()
A = L()
d = {}
for ele in A:
	d[ele] = set()
for i in range(m):
	(x, y) = L()
	x = A[x - 1]
	y = A[y - 1]
	if x == y:
		continue
	d[x].add(y)
	d[y].add(x)
z = sorted(list(d.keys()))
mx = -1
idx = 0
for ele in z:
	if len(d[ele]) > mx:
		mx = len(d[ele])
		idx = ele
print(idx)
endtime = time.time()


from sys import stdin
from collections import defaultdict
input = stdin.readline

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

def dfs():
	for i in range(n):
		k = color[i]
		if k not in count:
			count[k] = set()
		for j in tree[i]:
			if color[j] != k:
				count[k].add(color[j])
count = defaultdict()
(n, m) = put()
tree = [[] for i in range(n)]
color = list(put())
for _ in range(m):
	(x, y) = put()
	tree[x - 1].append(y - 1)
	tree[y - 1].append(x - 1)
dfs()
(index, ans) = (1000000000.0, 0)
for (i, s) in count.items():
	if len(s) > ans:
		(ans, index) = (len(s), i)
for (i, s) in count.items():
	if len(s) == ans and i < index:
		index = i
print(index)