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

a.sort(key=int)
b.sort(key=int)

if int(a[0]) == int(b[0]):
    print(int(a[0]))
elif int(a[0]) < int(b[0]):
    print("{}{}".format(a[0], b[0]))
else:
    print("{}{}".format(b[0], a[0]))
		 			 		 					   				  	    	