#coding: utf-8

entrada = raw_input()
entrada2 = list(map(int, raw_input().split()))
entrada3 = list(map(int, raw_input().split()))

entrada2.sort()
entrada3.sort()

men1 = min(entrada2)
men2 = min(entrada3)

def busca(lista, elem):
	metade = len(lista)/2
	result = False
	if lista[metade] < elem and metade > 0:
		result = busca(lista[metade:], elem)
	elif lista[metade] > elem and metade > 0:
		result = busca(lista[:metade], elem)
	elif lista[metade] == elem:
		return True
	return result

result = -1
for i in range(len(entrada2)):
	if busca(entrada3, entrada2[i]):
		result = entrada2[i]
		break

if result == -1 and men1 < men2:
	print str(men1) + str(men2)
elif result == -1 and men1 > men2:
	print str(men2) + str(men1)
else:
	print result