C# Solution using BFS
Not quite sure of the complexity though it might be T: O(nmlogn).\n\nInterestingly, I had a timeout error because I was using a List as Visited. That taught me 
Not quite sure of the complexity though it might be T: O(n*m*logn).\n\nInterestingly, I had a timeout error because I was using a List as Visited. That taught me to use a bool[] in order to keep the values instead of a list as when searching, it\'s much faster.\n\n```\npublic class Solution {\n    \n    private List<(int r, int c)> Directions = new List<(int r, int c)>{\n        (0, 1),\n        (0, -1),\n        (1, 0),\n        (-1, 0)\n    };\n    \n    public int CutOffTree(IList<IList<int>> forest) {\n        \n        var treesToCut = new List<int>();\n        for(int i = 0; i < forest.Count; i++)\n            for(int j = 0; j < forest[0].Count; j++)\n                if(forest[i][j] > 1)\n                    treesToCut.Add(forest[i][j]);\n        \n        treesToCut = treesToCut.OrderBy(x => x).ToList();\n        \n        // BFS\n        var totalSteps = 0;\n        (int r, int c) location = (0, 0);\n        foreach(var tree in treesToCut)\n        {\n            var queue = new Queue<(int r, int c)>();\n            var visited = new bool[forest.Count, forest[0].Count];\n            queue.Enqueue(location);\n            visited[location.r, location.c] = true;;\n            \n            var currentSteps = 0;\n            var found = false;\n            \n            if(forest[location.r][location.c] == tree)\n                found = true;\n            \n            while(queue.Count != 0 && !found)\n            {\n                currentSteps++;\n                \n                var currentLevelNodes = queue.Count();\n                while(currentLevelNodes > 0 && !found)\n                {\n                    var curr = queue.Dequeue();\n                    \n                    foreach(var dir in Directions)\n                    {\n                        var r = curr.r + dir.r;\n                        var c = curr.c + dir.c;\n                        \n                        if(0 <= r && r < forest.Count \n                           && 0 <= c && c < forest[0].Count \n                           && !visited[r, c] && forest[r][c] > 0){\n                            queue.Enqueue((r, c));\n                            visited[r, c] = true;;\n                            if(forest[r][c] == tree){\n                                location = (r, c);\n                                found = true;\n                            }\n                        }\n                    }\n                    currentLevelNodes--;\n                }\n            }\n            \n            if(!found)\n                return -1;\n            \n            totalSteps += currentSteps;\n        }\n        return totalSteps;\n    }\n}\n```
[]