C++ solution 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: O(M*N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(M*N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minimumTime(vector<vector<int>>& grid) {\n        int m=grid.size(),n=grid[0].size();\n\n        if(grid[0][1]>1 && grid[1][0]>1) return -1;\nint dir[]={1,0,-1,0,1};\n       vector<vector<bool>> vis(m,vector<bool>(n,false));\n       \n        priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>> pq;\n\n        pq.push({grid[0][0],0,0});\n\n        while(!pq.empty()){\n            int time=pq.top()[0],r=pq.top()[1],c=pq.top()[2];\n            pq.pop();\n\n            if(r==m-1 && c==n-1) return time;\n\n            if(vis[r][c]) continue;\n            vis[r][c]=true;\n\n            for(int i=0;i<4;i++){\n                int nr=r+dir[i],nc=c+dir[i+1];\n\n                if(nr<0 || nc<0 || nr>=m || nc>=n || vis[nr][nc]) continue;\n\n                int wait=(grid[nr][nc]-time)%2==0?1:0;\n\n                pq.push({max(grid[nr][nc]+wait,time+1),nr,nc});\n            }\n\n        }\n\n        return -1;\n    }\n};\n```
['C++']