n, m = map(int, raw_input().split())
a1 = []
b1 = []
for i in range(10):
	a1.append(0)
	b1.append(0)
a = map(int, raw_input().split())
b = map(int, raw_input().split())
for i in range(len(a)):
	a1[a[i]] = 1
for i in range(len(b)):
	b1[b[i]] = 1
ck = 0			
for i in range(1, 10):
	if(b1[i] == a1[i] and b1[i] == 1):
		ck = i
		break
if(ck > 0):
	print ck	
elif(min(a) > min(b)):
	print (10*min(b) + min(a))
else:
	print (10*min(a) + min(b))		
