n, m = map(int, raw_input().split(' '))

first = map(int, raw_input().split(' '))
second = map(int, raw_input().split(' ')) 

firstList = []
secondList = []


i = 0

while i<n:
	if first[i]>0:
		firstList.append(first[i])
	i+=1
		
i = 0

while i<m:
	if second[i]>0:
		secondList.append(second[i])
	i+=1

firstMin = firstList[0]
i = 1

while i<=(len(firstList)-1):
	if firstList[i]<firstMin:
		firstMin = firstList[i]
	i+=1


secondMin = secondList[0]
i = 1

while i<=(len(secondList)-1):
	if secondList[i]<secondMin:
		secondMin = secondList[i]
	i+=1
	
	

if firstMin<secondMin:
	number = firstMin*10 + secondMin
elif secondMin<firstMin:
	number = secondMin*10 + firstMin
else:
	number = firstMin
	
print(number)
