Heap/PriorityQueue || Java || Dijkstra || Clean code
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:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public static int max = (int) (1e9);\n    public static final int[][] moves = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n\n    public static class Pair {\n        public int r, c, ele, offset;\n\n        public Pair(\n                final int r,\n                final int c,\n                final int ele,\n                final int offset) {\n            this.r = r;\n            this.c = c;\n            this.ele = ele;\n            this.offset = offset;\n        }\n    }\n\n    public int minTimeToReach(int[][] moveTime) {\n        final int n = moveTime.length;\n        final int m = moveTime[0].length;\n        final int[][] weights = new int[n][m];\n        final PriorityQueue<Pair> queue = new PriorityQueue<>((a, b) -> a.ele - b.ele);\n\n        for (int i = 0; i < n; i++) Arrays.fill(weights[i], max);\n\n        weights[0][0] = moveTime[0][0] = 0;\n        queue.add(new Pair(0, 0, moveTime[0][0], 2));\n\n        while(!queue.isEmpty()) {\n            final Pair curPair = queue.remove();\n\n            if (curPair.r == n - 1 && curPair.c == m - 1) return weights[n - 1][m - 1];\n\n            for (final int[] move : moves) { \n                final int childR = curPair.r + move[0]; \n                final int childC = curPair.c + move[1];\n                final int curOffset = (curPair.offset == 2 ? 1 : 2);\n\n                if (childR < 0 \n                    || childR >= n\n                    || childC < 0 \n                    || childC >= m) continue;\n\n                if (weights[childR][childC] == max \n                    || weights[childR][childC] > weights[curPair.r][curPair.c] + 1) {\n                    weights[childR][childC] = Integer.max(moveTime[childR][childC], weights[curPair.r][curPair.c]) + curOffset;\n\n                    queue.add(new Pair(childR, childC, weights[childR][childC], curOffset));\n                }\n            }\n        }\n\n        // Arrays.stream(weights).forEach(x -> System.out.println(Arrays.toString(x)));\n\n        return -1;\n    }\n}\n```
['Java']