implements find min path