find total minimum distance