✅ Simple Java Solution + Heap
CODE\nJava []\nint[][] dirs = new int[][]{{-1,0}, {1,0}, {0,-1}, {0,1}};\npublic int minTimeToReach(int[][] moveTime) {\n    int n=moveTime.length, m = moveTime
## **CODE**\n```Java []\nint[][] dirs = new int[][]{{-1,0}, {1,0}, {0,-1}, {0,1}};\npublic int minTimeToReach(int[][] moveTime) {\n    int n=moveTime.length, m = moveTime[0].length;\n    PriorityQueue<int[]> pq = new PriorityQueue<>((a,b)->a[2]-b[2]);\n\t\n\t// 0 -> R, 1 -> C, 2 -> Cost to Reach that Room, 3 -> First or Second Move\n    pq.add(new int[]{0,0,0,1});\n    \n    int dp[][] = new int[n][m];\n    for(int[] arr: dp) Arrays.fill(arr, -1);\n    dp[0][0] = 0;\n    \n    while(!pq.isEmpty()) {\n        int[] top = pq.remove();\n        int r=top[0], c=top[1], add = top[3];\n        \n        for(int[] dir : dirs) {\n            int nr=r+dir[0], nc=c+dir[1];\n            if(nr<0 || nc<0 || nr==n || nc==m) continue;\n            \n            int cost = Math.max(moveTime[nr][nc], top[2]) + add;\n            if(nr == n-1 && nc == m-1) return cost;\n            \n            if(dp[nr][nc] == -1 || dp[nr][nc] > cost) {\n                dp[nr][nc] = cost;\n                pq.add(new int[]{nr,nc,cost,(top[3]==1)? 2: 1});\n            }\n        }\n    }\n    return -1;\n}\n```
['Java']