input()
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
a, b = ((a, b) if len(a) < len(b) else (b, a))
for x in a:
	if x in b:
		print(x)
		exit(0)
print(min(a, b) * 10 + max(a, b))