n, m = input().split()
ais = list(map(int, input().split()))
bis = list(map(int, input().split()))

#print(n, m)
#print(ais)
#print(bis)


cminfortwo = 10

for e in ais:
	if e in bis:
		cminfortwo = min(e, cminfortwo)

if cminfortwo<10:
	print(cminfortwo)
else:
	mia = min(ais)
	mib = min(bis)
	print(min(mia,mib), max(mia, mib), sep="")


