a,b=map(int,raw_input().split())
l=raw_input().split()
l1=raw_input().split()
ans=min(int(min(l)+min(l1)),int(min(l1)+min(l)))
for i in l:
	if i in l1:
		ans=min(ans,int(i))
for i in l1:
	if i in l:
		ans=min(ans,int(i))
print ans
