n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
for i in a:
	if i in b:
		print(i)
		exit(0)
print(min(a[0], b[0])*10+max(a[0], b[0]))