x = map(int, raw_input().split())
y = map(int, raw_input().split())
z = map(int, raw_input().split())

y.sort()
z.sort()

if y == z:		
	if min(y) == min(z):
		print str(min(y))

elif y[0] == z[0]:
	print str(y[0]) 

else:
	print str(min(y)) + str(min(z))
