using priority queue
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```cpp []\n\nclass Solution {\npublic:\n   \n    \n    int minTimeToReach(vector<vector<int>>& mt) {\n          int n=mt.size();\n       int m=mt[0].size();\n\n     \nint rr[4]={1,-1,0,0};\nint cc[4]={0,0,-1,1};\n       priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>>pq;\n\n       vector<vector<int>>vis(n,vector<int>(m,0));\n\n       pq.push({0,1,0,0});\n       vis[0][0]=1;\n\n       while(!pq.empty()){\n        auto it=pq.top();\n        pq.pop();\n\n        int time=it[0];\n        int stp=it[1];\n       \n        int x=it[2];\n        int y=it[3];\n        if(x==n-1&&y==m-1){\n            return time;\n        }\n        for(int k=0;k<4;k++){\n            int newr=rr[k]+x;\n            int newc=cc[k]+y;\n            if(newr>=0&&newr<n&&newc>=0&&newc<m&&vis[newr][newc]==0){\n                int newtime=max(time,mt[newr][newc])+stp;\n\n                int newstp=2;\n                if(stp==2){\n                    newstp=1;\n                }\n               \n\n\n                pq.push({newtime,newstp,newr,newc});\n                vis[newr][newc]=1;\n            }\n        }\n       }\n       return 0;\n    }\n};\n\n```
['Heap (Priority Queue)', 'C++']