s=[int(n) for n in input().split()]
a=[int(n) for n in input().split()]
b=[int(n) for n in input().split()]
z=[]
for n in range(len(a)):
	for k in range(len(b)):
		if a[n]!=b[k]:
			z.append(min(a[n],b[k])*10+max(a[n],b[k]))
		else:
			z.append(a[n])
print(min(z))