x = map(int, raw_input().split())
y = map(int, raw_input().split())
z = map(int, raw_input().split())

cont = 0
index = 0

z.sort()
y.sort()

if len(y) == 1 and len(z) > 1:
	print y[0]
elif len(z) == 1 and len(y) > 1:
	print z[0]

elif len(y) > len(z):
	for i in range(len(y)):
		if y[i] in z:
			print y[i]
			cont += 1
			break
			
	if cont == 0:		
		if str(min(y)) > str(min(z)):
			print str(min(z)) + str(min(y))
			
		elif str(min(y)) < str(min(z)):
			print str(min(y)) + str(min(z))
			
		else:
			print str(min(y))


			
elif len(y) == len(z):
	for i in range(len(z)):
		if z[i] in y:
			cont += 1	
	
	if cont == 0:		
		if str(min(y)) > str(min(z)):
			print str(min(z)) + str(min(y))
			
		elif str(min(y)) < str(min(z)):
			print str(min(y)) + str(min(z))
			
		else:
			print str(min(y))
	elif cont == len(y):
		print str(min(y))
	else:
		for i in range(len(z)):
			if z[i] in y:
				print z[i]
				break
		
							
				
elif len(y) < len(z):
	for i in range(len(z)):
		if z[i] in y:
			print z[i]
			cont += 1
			break
	
	if cont == 0:		
		if str(min(y)) > str(min(z)):
			print str(min(z)) + str(min(y))
			
		elif str(min(y)) < str(min(z)):
			print str(min(y)) + str(min(z))
			
		else:
			print str(min(y))
			
