q, b = raw_input().split()
lista_1 = [int(i) for i in raw_input().split()]
lista_2 = [int(i) for i in raw_input().split()]
lista_1.sort()
lista_2.sort()

m=10

for e in lista_1:
	
	if e in lista_2 and e < m:
		m=e

if m < 10:
	print m

else:
	x = (lista_1[0])
	a = (lista_2[0])

	if a == x:
		print x

	else:
		
		if a > x:
			print "%d%d" % (x,a)
		else:
			print "%d%d" % (a,x)
