raw_input()
lista1 = raw_input().split()
lista2 = raw_input().split()
lista = []

for k in lista1:
	for l in lista2:
		if k != l:
			lista.append(int(k + l))
			lista.append(int(l + k))
			
		else :
			lista.append(int(k))
lista.sort()
print lista[0]
