Java 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(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int minimumTime(int[][] grid) {\n        // If both initial moves require more than 1 second, impossible to proceed\n        if (grid[0][1] > 1 && grid[1][0] > 1) {\n            return -1;\n        }\n\n        int rows = grid.length, cols = grid[0].length;\n        // Possible movements: down, up, right, left\n        int[][] directions = { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } };\n        boolean[][] visited = new boolean[rows][cols];\n\n        // Priority queue stores {time, row, col}\n        // Ordered by minimum time to reach each cell\n        PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) ->\n            Integer.compare(a[0], b[0])\n        );\n        pq.add(new int[] { grid[0][0], 0, 0 });\n\n        int minTime = -1;\n        while (!pq.isEmpty()) {\n            int[] curr = pq.poll();\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 (int[] 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 = ((grid[nextRow][nextCol] - time) % 2 == 0)\n                    ? 1\n                    : 0;\n                int nextTime = Math.max(\n                    grid[nextRow][nextCol] + waitTime,\n                    time + 1\n                );\n                pq.add(new int[] { nextTime, nextRow, nextCol });\n            }\n        }\n        return minTime;\n    }\n\n    // Checks if given cell coordinates are valid and unvisited\n    private boolean isValid(boolean[][] visited, int row, int col) {\n        return (\n            row >= 0 &&\n            col >= 0 &&\n            row < visited.length &&\n            col < visited[0].length &&\n            !visited[row][col]\n        );\n    }\n}\n```
['Array', 'Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'Matrix', 'Shortest Path', 'Java']