n , m = map(int,input().split())
l1 = sorted(list(map(int,input().split())))
l2 = sorted(list(map(int,input().split())))
flag = 0
for i in l1:
	if i in l2:
		flag = 1
		print(i)
		break
if flag==0:
	a = str(l1[0])+str(l2[0])
	b = str(l2[0])+str(l1[0])
	print(min(int(a),int(b)))