def consoleInput(counter1, counter2):
	mass1 = []
	twice = 0
	
	tempo = input()
	for i in range(counter1):
		mass1.append(int(tempo[i*2]))
		if i == 0:
			min1 = int(mass1[i])
		elif mass1[i] < min1:
			min1 = int(mass1[i])
	
	tempo = input()
	for i in range(counter2):
		temp = int(tempo[i*2])
		if i == 0:
			min2 = temp
		elif temp < min2:
			min2 = temp
			
		if temp in mass1 and (temp < twice or twice == 0):
			twice = temp
	
	return [min1, min2, twice]

temp = input()
c1 = int(temp[0])
c2 = int(temp[2])

mass = consoleInput(c1, c2)

if mass[0] == mass[1]:
	d = mass[0]
elif mass[0] < mass[1]:
	d = mass[0] * 10 + mass[1]
else:
	d = mass[1] * 10 + mass[0]
	
if mass[2] < d and not mass[2] == 0:
	d = mass[2]

print(d)