n, m = map(int, input().split(" "))
a = set(map(int, input().split()))
b = set(map(int, input().split()))

if len(a & b) != 0: 
	print(min(a & b)) 
else:
	print(min(min(a)*10+min(b),min(b)*10+min(a)))
