n = map(int,raw_input().split(' '))
a = map(int,raw_input().split(' '))
b = map(int,raw_input().split(' '))
v = 999
for i in a:
	if i in b and i<v:
		v = i
m = int(str(min(a))+str(min(b)))
if v<m:
	print v 
else:
	print m
