n1,n2=input().split(" ")
l1=input().split(" ")
l2=input().split(" ")

l=[]

for i in l1:
	if i in l2:
		l.append(i)

if len(l)!=0:
	print(min(l))
else:
	m1=min(l1)
	m2=min(l2)	
	if m1<m2:
		print(m1+m2)
	else:
		print(m2+m1)		