n, m = map(int, raw_input().split())
l1 = map(int, raw_input().split())
l2 = map(int, raw_input().split())
n1 = min(l1)
n2 = min(l2)
i = set(l1).intersection(set(l2))
if (len(i) > 0):
	print min(i)
else:
	print min(n1,n2)*10 + max(n1,n2)
