
n, m = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))

l1.sort()
l2.sort()

l = []
for i in l1:
	if i in l2:
		l.append(i)
		break
l.append(l1[0] * 10 + l2[0])
l.append(l2[0] * 10 + l1[0])
print(min(l)) 