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(a[0])
elif int(a[0]) < int(b[0]):
  print("%d%d" % (int(a[0]), int(b[0])))
else:
  print("%d%d" % (int(a[0]), int(b[0])))

	 		   	 		  		 			 	  		   			