JAVA DP + PQ SOLUTION
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    static class Pair implements Comparable<Pair>{\n        int x;\n        int y;\n        int time;\n        int breakt;\n        public Pair(int i, int j, int t,int b){\n            this.x=i;\n            this.y=j;\n            this.time=t;\n            this.breakt=b;\n        }\n\n        @Override \n        public int compareTo(Pair p2){\n            return this.time-p2.time;\n        }\n    }\n    public int minTimeToReach(int[][] moveTime) {\n        int n=moveTime.length;\n        int m=moveTime[0].length;\n\n        int dp[][]= new int [n][m];\n       \n         int[] dx = {1, 0, -1, 0};\n        int[] dy = {0, -1, 0, 1};\n        \n       PriorityQueue<Pair> pq= new PriorityQueue<>();\n        pq.add(new Pair(0,0,0,1)); \n\n        for(int k=0;k<n;k++){\n            Arrays.fill(dp[k],Integer.MAX_VALUE);\n        }\n\n        dp[0][0] =0;  \n        \n        while(!pq.isEmpty()) {\n            Pair curr = pq.remove();\n            int x = curr.x;\n            int y = curr.y;\n            int time = curr.time;\n            int br= curr.breakt;\n\n           for(int i=0;i<4;i++) {\n                int nx = x + dx[i];\n                int ny = y + dy[i];\n\n              if(nx >= 0 && nx < n && ny >= 0 && ny < m) {\n                    int nextTime = time+br;\n                    int nextBreak =(br == 1) ? 2 : 1;\n\n                    if (time >= moveTime[nx][ny]) { \n                        if (dp[nx][ny] > nextTime) {\n                            dp[nx][ny] = nextTime;\n                            pq.add(new Pair(nx, ny, nextTime, nextBreak));\n                        }\n                    } else { \n                        int waitTime = moveTime[nx][ny] + br;\n                        if (dp[nx][ny]>waitTime) {\n                            dp[nx][ny]=waitTime;\n                            pq.add(new Pair(nx, ny, waitTime, nextBreak));\n                        }\n                    }\n                    \n                   \n            }\n           }\n        }\n\n        \n        return dp[n-1][m-1];\n        \n    }\n\n   \n}\n\n```
['Java']