n, m = map(int, input().split())

nas = list(map(int, input().split()))

mas = list(map(int, input().split()))

minn = []

minn.append(10)

minn.append(15)

h = 0

g = 0

for i in range(n):

	for j in range(m):

		if nas[i] == mas[j]:

			minn.append(nas[i])

if min(minn) != 10 :

	print(min(minn))

else:

	if min(nas) >= min(mas):

		h = min(mas)

		g = min(nas)

	else:

		h = min(nas)

		g = min(mas)

	print(h*10 + g)