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

arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))

if min(arr1) == min(arr2):
	print(min(arr2))
else:
	print(str(min(arr1)) + str(min(arr2)))