def repeated(x):
	return x in sec_list

def pretty_integer():
	if len(rpt) > 0:
		return min(rpt)
	x, y = min(fst_list), min(sec_list)
	return "%d%d" %(min(x,y), max(x,y))

n, m = raw_input().split()
fst_list = map(int, raw_input().split())
sec_list = map(int, raw_input().split())
rpt = filter(repeated, fst_list)
print pretty_integer()