n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
w=min(a)
w1=min(b)
q=set(a).intersection(set(b))
if len(q)!=0:
	print(min(q))
else:
	print("{}{}".format(min(w,w1),max(w,w1)))