def pretty_integer():
	min1, min2 = min(first_list), min(second_list)
	if min1 == min2:
		return min1
	elif min1 < min2:
		return "%d%d" %(min1, min2)
	else:
		return "%d%d" %(min2, min1)

n, m = raw_input().split()
first_list = map(int, raw_input().split())
second_list = map(int, raw_input().split())
print pretty_integer()
