Python solution(Dijkstra)
Complexity\n- Time complexity: O(N*M(logNM))\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(NM)\n Add your space complexity here, e.g. O(n)
# Complexity\n- Time complexity: O(N*M(logNM))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(NM)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def minTimeToReach(self, moveTime: List[List[int]]) -> int:\n        if not moveTime:\n            return -1\n        n, m = len(moveTime), len(moveTime[0])\n        queue = [(0, 1, 0, 0)] # (arrivetime, step, row, col)\n        visited = set((0, 0))\n\n        while queue:\n            time, step, r, c = heapq.heappop(queue)\n            print(time, step, r, c)\n            if r == n - 1 and c == m - 1:\n                print(r, c)\n                return time\n            for dr, dc in [(1, 0), (-1, 0), (0, 1), (0, -1)]:\n                nr, nc = r +  dr, c + dc\n                if 0 <= nr < n and 0 <= nc < m and (nr, nc) not in visited:\n                    visited.add((nr, nc))\n                    if step == 1:\n                        newtime = max(time, moveTime[nr][nc]) + 1\n                        heapq.heappush(queue, [newtime, 2, nr, nc])\n                    else:\n                        newtime = max(time, moveTime[nr][nc]) + 2\n                        heapq.heappush(queue, [newtime, 1, nr, nc])\n                    \n\n```
['Python3']