n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=[]
q=[]
for i in range(n):
	if a[i] in b:
		s.append(a[i])
for i in range(m):
	if b[i] in a:
		q.append(b[i])	
if len(s)==len(q)==0:
	print(min(min(a),min(b)),max(min(a),min(b)),sep='')
elif min(s)==min(q):
	print(min(s))
else:
	print(min(min(s),min(q)),max(min(s),min(q)),sep='')