def breakdown(num):
	broken=[]
	while(num is not 0):
		r = num%10
		broken.append(r)
		num=int(num/10)
	return broken 

userip = input('').split(' ')
n = int(userip[0])
m = int(userip[1])
firstlist = []
secondlist = []
firstlist = [int(i) for i in input('').split(' ')]
secondlist = [int(i) for i in input('').split(' ')]
testnum = 1
while(True):
	if(testnum<10):
		if(testnum in firstlist and testnum in secondlist):
			break 
	else:
		b,a = breakdown(testnum)
		if((a in firstlist and b in secondlist) or (a in secondlist and b in firstlist)):
			break 
	testnum+=1
print(testnum)
  	 	  	  	     			  			 		  	