def main():
	(n, m) = (int(x) for x in input().split())
	A = set([int(x) for x in input().split()])
	B = set([int(x) for x in input().split()])
	print(solver(A, B))

def solver(A, B):
	cup = A & B
	if len(cup) != 0:
		return cup.pop()
	else:
		a = min(A)
		b = min(B)
		s, l = min(a, b), max(a, b)
		return 10 * s + l

main()	