x = raw_input().split(" ")

n = raw_input().split(" ")
m = raw_input().split(" ")

n.sort()
m.sort()

if(m[0] == n[0]):
	print(int(m[0]))

else:
	if (m[0] > n[0]):
		c = n[0]+m[0]
		print(int(c))
	else:
		c = m[0]+n[0]
		print(int(c))