n, m = map(int, raw_input().split())
a = map(int, raw_input().split())
b = map(int, raw_input().split())
c = []
for i in xrange(len(a)):
	for j in xrange(len(b)):
		if a[i] == b[j]:
			if a[i] not in c:
				c.append(a[i])
		else:
			aux = int(str(a[i]) + str(b[j]))
			if aux not in c:
				c.append(aux)
print min(c)
