n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for elem in a:
	if elem in b:
		c.append(elem)

if c:
	print(min(c))
else:
	if min(min(a), min(b)) == max(min(a), min(b)):
		print(min(min(a), min(b)))
	else:
		print(str(min(min(a), min(b))) + str((max(min(a), min(b)))))