lenLists = [int(n) for n in input().split(' ')]

def getMin(array):
	index = -1
	for item in array:
		index += 1
		if index == 0:
			mn = item
			continue
		elif item < mn:
			mn = item
	return mn

lines = []
for array in lenLists:
	digits = [int(n) for n in input().split(' ')]
	lines.append(digits)

emComum = []
for digit in lines[0]:
	if digit in lines[1]:
		emComum.append(digit)

number = []
if len(emComum) == 0:
	menor1 = getMin(lines[0])
	number.append(menor1)
	menor2 = getMin(lines[1])
	number.append(menor2)
	menor = menor1 if menor1 < menor2 else menor2
	maior = menor2 if menor1 < menor2 else menor1
	
	number = int(str(menor) + str(maior))
else:
	number = getMin(emComum)

print(number)
   	  	   		  		  	  	  			 	 	