x,y = map(int, input().split())
first = list(map(int, input().split()))
second = list(map(int, input().split()))
mf = min(first)
ms = min(second)
if x < y:
	first.sort()
	second.sort()
	for c in first:
		if c in second:
			resp = c
			break
		else:
			if ms > mf:
				resp = str(mf) + str(ms)
			elif ms == mf:
				resp = ms
			else:
				resp = str(ms) + str(mf)
else:
	first.sort()
	second.sort()
	for c in second:
		if c in first:
			resp = c
			break
		else:
			if ms > mf:
				resp = str(mf) + str(ms)
			elif ms == mf:
				resp = ms
			else:
				resp = str(ms) + str(mf)

resp = int(resp)
print(resp)
