[Java] Easy solution with min Heap
java\nclass Solution {\n    public int minTimeToReach(final int[][] moveTime) {\n        final int n = moveTime.length, m = moveTime[0].length;\n        final Q
```java\nclass Solution {\n    public int minTimeToReach(final int[][] moveTime) {\n        final int n = moveTime.length, m = moveTime[0].length;\n        final Queue<int[]> queue = new PriorityQueue<>((a, b) -> a[2] - b[2]);\n        final int[][] dp = new int[n][m];\n        final int[][] directions = new int[][] { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } };\n\n        for(final int[] d : dp)\n            Arrays.fill(d, Integer.MAX_VALUE);\n\n        queue.offer(new int[] { 0, 0, 0, 1 });\n        moveTime[0][0] = 0;\n\n        while(!queue.isEmpty()) {\n            final int[] curr = queue.poll();\n            final int i = curr[0], j = curr[1], t = curr[2], cost = curr[3];\n\n            if(i == n - 1 && j == m - 1)\n                return t;\n\n            if(dp[i][j] <= t)\n                continue;\n\n            dp[i][j] = t;\n\n            for(final int[] direction : directions) {\n                final int x = i + direction[0], y = j + direction[1];\n\n                if(x < n && y < m && x >= 0 && y >= 0 && dp[x][y] == Integer.MAX_VALUE) {\n                    final int newTime = Math.max(t, moveTime[x][y]) + cost;\n                    queue.offer(new int[] { x, y, newTime, cost == 1 ? 2 : 1 });\n                }\n            }\n        }\n\n        return -1;\n    }\n}\n```
['Java']