Python (Simple Dijkstra's algorithm)
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def minimumTime(self, grid):
        m, n = len(grid), len(grid[0])

        if grid[0][1] > 1 and grid[1][0] > 1:
            return -1

        stack, dict1 = [(0,0,0)], {}

        for i in range(m):
            for j in range(n):
                dict1[(i,j)] = float("inf")

        dict1[(0,0)] = 0 

        while stack:
            time,x,y = heapq.heappop(stack)

            if x == m-1 and y == n-1:
                return time 

            for (nx,ny) in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
                if 0 <= nx < m and 0 <= ny < n:
                    if time+1 >= grid[nx][ny]:
                        new_time = time+1 
                    else:
                        if (grid[nx][ny]-time)%2 == 0:
                            new_time = grid[nx][ny]+1
                        else:
                            new_time = grid[nx][ny]

                    if dict1[(nx,ny)] > new_time:
                        dict1[(nx,ny)] = new_time 
                        heapq.heappush(stack,(dict1[(nx,ny)],nx,ny))

        return -1 
```
['Python3']