al,bl = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

t = a if al >= bl else b
m = []
for i in (a if al < bl else b):
	if i in t:
		m.append(i)


if m:
	print(min(m))
else:
	
	m1 = min(a)
	m2 = min(b)

	if m1*10+m2 < m2*10+m1:
		print(m1*10+m2)
	else:
		print(m2*10+m1)
