n,m = map(int,input().split())
n1 = list(map(int,input().split()))
m1 = list(map(int,input().split()))
k = set(n1).intersection(set(m1))
if len(k)!=0:
	print(min(k))
else:
	print([min(m1)*10+min(n1),min(n1)*10+min(m1)][min(n1)<min(m1)])