a, b = raw_input().split()
lista_1 = [int(i) for i in raw_input().split()]
lista_2 = [int(i) for i in raw_input().split()]

x = min(lista_1)
a = min(lista_2)

if a == x:
	print x

else:
	
	if a in lista_1:
		print a
	
	elif a > x:
		print "%d%d" % (x,a)
	else:
		print "%d%d" % (a,x)
