a,b=map(int,input().split())
l=list(map(int,input().split()))
k=list(map(int,input().split()))
l.sort()
k.sort()
f=0
if a<=b:
	for x in l:
		if x in k:
			print(x)
			f=1
			break
else:
	for x in k:
		if x in l:
			print(x)
			f=1
			break
if f==0:
	if l[0]<=k[0]:print(str(l[0])+str(k[0]))
	else:print(str(k[0])+str(l[0]))