Swift Solution using Dijkstra's
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(nm*log(nm))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:  $$O(n*m)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```swift []\nimport Collections\n\nclass Solution {\n    func minTimeToReach(_ moveTime: [[Int]]) -> Int {\n\n        var minHeap = Heap<Path>()\n        var visitedWithTime = Array(repeating: Array(repeating: Int.max, count: moveTime[0].count), count: moveTime.count)\n        \n        minHeap.insert(Path(r: 0, c: 0, timePassed: 0, nextMoveCost: 1))\n        // [[0,4],[4,4]]\n        while let currPath = minHeap.popMin() {\n            // print(currPath)\n            if currPath.r == moveTime.count - 1 && currPath.c == moveTime[0].count - 1 {\n                return currPath.timePassed\n            }\n            \n            for (dR, dC) in [(-1,0), (1,0), (0, -1), (0, 1)] {\n                \n                let newRow = currPath.r + dR, newCol = currPath.c + dC\n                guard (0..<moveTime.count).contains(newRow) && (0..<moveTime[0].count).contains(newCol) else { continue }\n                let timeAtNewCell = currPath.timePassed >= moveTime[newRow][newCol] ? currPath.timePassed + currPath.nextMoveCost : moveTime[newRow][newCol] + currPath.nextMoveCost\n                // print(timeAtNewCell)\n                guard timeAtNewCell < visitedWithTime[newRow][newCol]  else { continue }\n                // print(newRow, newCol, timeAtNewCell)\n                visitedWithTime[newRow][newCol] = timeAtNewCell\n                minHeap.insert(Path(r: newRow, c: newCol, timePassed: timeAtNewCell, nextMoveCost: currPath.nextMoveCost == 1 ? 2 : 1 ))\n                \n            }\n        }\n        return -1\n    }\n}\n\nstruct Path: Comparable, CustomStringConvertible {\n    let r: Int\n    let c: Int\n    let timePassed: Int\n    let nextMoveCost: Int\n    var description: String { "r: \\(r), c: \\(c), timePassed: \\(timePassed), nextMoveCost: \\(nextMoveCost)" }\n\n    static func == (lhs: Self, rhs: Self) -> Bool {\n        return lhs.r == rhs.r && lhs.c == rhs.c && lhs.timePassed == rhs.timePassed\n    }\n\n    static func < (lhs: Self, rhs: Self) -> Bool {\n        if lhs.timePassed == rhs.timePassed {\n            if rhs.nextMoveCost == rhs.nextMoveCost {\n                if lhs.r == rhs.r { return lhs.c < rhs.c }\n                return lhs.r < rhs.r     \n            }\n            \n            return lhs.nextMoveCost < rhs.nextMoveCost\n        }\n        return lhs.timePassed < rhs.timePassed\n    }\n}\n\n```
['Swift']