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

firstList = map(int, raw_input().split(' '))
secondList = map(int, raw_input().split(' ')) 


firstMin = firstList[0]
i = 1

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


secondMin = secondList[0]
i = 1

while i<=(m-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)
