a =  input('')
spl = a.split(' ')
an = []
if len(spl)==2  and int(spl[0]) in range (1,10) and int(spl[1]) in range (1,10) :
	for n in range(0,2):
		b= input('')
		if len (b.split(' ')) == int(spl[n]): 
			for i in b.split(' '):
				if int(i) in range(1,10):pass
				else:raise NameError('erro!')
			ak = min(b.split(' '))
			an.append(ak)
		else:raise NameError('erro!')
	if int(an[0]) == int(an[1]):print(str(an[0]))
	if int(an[0]) > int(an[1]) :print(str(an[1])+str(an[0]))
	if int(an[0])< int(an[1]):print(str(an[0])+str(an[1]))	
else:raise NameError('erro!')
