n,m = [int(nm) for nm in raw_input().split(" ")]
a = [int(ai) for ai in raw_input().split(" ")]
b = [int(bi) for bi in raw_input().split(" ")]
x = min(a)
y = min(b)
if x == y:
	print x
elif x > y:
	if x in b:
		print x
	else:
		print str(y)+str(x)
else:
	if y in a:
		print y
	else:
		print str(x)+str(y)