C++ 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: O(m * n log(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```cpp []\nclass Solution {\npublic:\n    int minimumTime(vector<vector<int>>& grid) {\n        // If both initial moves require more than 1 second, impossible to\n        // proceed\n        if (grid[0][1] > 1 && grid[1][0] > 1) {\n            return -1;\n        }\n\n        int rows = grid.size(), cols = grid[0].size();\n        // Possible movements: down, up, right, left\n        vector<vector<int>> directions = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n        vector<vector<bool>> visited(rows, vector<bool>(cols, false));\n\n        // Priority queue stores {time, row, col}\n        // Ordered by minimum time to reach each cell\n        priority_queue<vector<int>, vector<vector<int>>, greater<>> pq;\n        pq.push({grid[0][0], 0, 0});\n\n        int minTime = -1;\n        while (!pq.empty()) {\n            auto curr = pq.top();\n            pq.pop();\n            int time = curr[0], row = curr[1], col = curr[2];\n\n            // Check if reached target\n            if (row == rows - 1 && col == cols - 1) {\n                minTime = time;\n                break;\n            }\n\n            // Skip if cell already visited\n            if (visited[row][col]) {\n                continue;\n            }\n            visited[row][col] = true;\n\n            // Try all four directions\n            for (auto& d : directions) {\n                int nextRow = row + d[0], nextCol = col + d[1];\n                if (!isValid(visited, nextRow, nextCol)) {\n                    continue;\n                }\n\n                // Calculate the wait time needed to move to next cell\n                int waitTime =\n                    ((grid[nextRow][nextCol] - time) % 2 == 0) ? 1 : 0;\n                int nextTime = max(grid[nextRow][nextCol] + waitTime, time + 1);\n                pq.push({nextTime, nextRow, nextCol});\n            }\n        }\n        return minTime;\n    }\n\nprivate:\n    // Checks if given cell coordinates are valid and unvisited\n    bool isValid(vector<vector<bool>>& visited, int row, int col) {\n        return row >= 0 && col >= 0 && row < visited.size() &&\n               col < visited[0].size() && !visited[row][col];\n    }\n};\n```
['Array', 'Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'Matrix', 'Shortest Path', 'C++']