n, m = raw_input().split(" ")
a, b = raw_input().split(" "), raw_input().split(" ")

if min(a) == min(b):
    print(min(a))
elif min(a) < min(b):
    print("{}{}".format(min(a), min(b)))
else:
    print("{}{}".format(min(b), min(a)))
	  	 	  		 			   	  	  			    	