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