n, m = map(int, input().split())

arr1 = input().split()
arr2 = input().split()

_min = 2147483647

for i in arr1:
	for j in arr2:
		if i == j and int(i) < _min:
			_min = int(i)
		elif min(int(i + j), int(j + i)) < _min:
			_min = min(int(i + j), int(j + i))

print(_min)