a=input()
b=10
c=10
x=input().split()
r=list()
for i in x:
	if int(i)<=b:
		b=int(i)
for j in input().split():
	if int(j)<=c:
		c=int(j)
	if j in x:
		r.append(int(j))
if len(r)!=0:
	print(min(r))
elif b>c:
	print(c*10+b)
else:
	print(b*10+c)