Very Easy To Understand Solution - Just Do Dry Run
Complexity
Time complexity: O(n×m×log(n×m))

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

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

# Code
```java []
class Solution {

    class Node {
        int x;
        int y;
        int time;
        int move;

        public Node(int x, int y, int time, int move) {
            this.x = x;
            this.y = y;
            this.time = time;
            this.move = move;
        }
    }

    public int minTimeToReach(int[][] moveTime) {
        int n = moveTime.length;
        int m = moveTime[0].length;
        int[][] time = new int[n][m];

        for (int i = 0; i < n; i++) {
            Arrays.fill(time[i], Integer.MAX_VALUE);
        }

        PriorityQueue<Node> pq = new PriorityQueue<>((node1, node2) -> node1.time - node2.time);
        pq.add(new Node(0, 0, 0 , 2));
        time[0][0] = 0;
        
        while (!pq.isEmpty()) {
            Node node = pq.poll();
            int x = node.x;
            int y = node.y;
            int currTime = node.time;
            int move = node.move;

            if(x == m-1 && y == n -1) return currTime;
            int newmove = (move == 1) ? 2 : 1;

            int[][] dirs = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };
            for (int[] dir : dirs) {
                int nodex = x + dir[0];
                int nodey = y + dir[1];
                if (nodex >= 0 && nodey >= 0 && nodex < n && nodey < m) {
                        
                        int newtime = newmove + Math.max(node.time, moveTime[nodex][nodey]);
                        if (newtime < time[nodex][nodey]) {
                            time[nodex][nodey] = newtime;
                            pq.add(new Node(nodex, nodey,newtime, newmove));
                        }
                }
            }
        }
        return time[n-1][m-1];
    }
}
```
['Java']