n, m = map(int, raw_input().split())
a = map(int, raw_input().split())
b = map(int, raw_input().split())	
if(min(a) == min(b)):
	print min(a)
elif(min(a) > min(b)):
	print (10*min(b) + min(a))
else:
	print (10*min(a) + min(b))		
