x = raw_input().split(" ")

n = raw_input().split(" ")
m = raw_input().split(" ")

n.sort()
m.sort()
valor = 0


for i in range(len(n)):
	if n[i] in m:
		valor = (n[i])
		break

if(valor ==0 ):
	if (m[0] > n[0]):
		valor = n[0]+m[0]
	
	else:
		valor = m[0]+n[0]
		
print (valor)
		