min_distance function
min_distance function