n,m = [int(nm) for nm in raw_input().split(" ")]
a = [int(ai) for ai in raw_input().split(" ")]
b = [int(bi) for bi in raw_input().split(" ")]
c = a + b
for ai in a:
	for bi in b:
		c += [int(str(ai)+str(bi))]
		c += [int(str(bi)+str(ai))]
print min(c)
