n,m=map(int,input().split())
fir=list(map(int,input().split()))
sec=list(map(int,input().split()))
inter=[val for val in fir if val in sec]
if inter!=[]:
	print(min(inter))
else:
	a=min(fir)
	b=min(sec)
	print(int(str(min(a,b))+str(max(a,b))))
