------
## 最终结论
```python
from collections import deque

def minFlips(mat):
    def to_tuple(matrix):
        return tuple(tuple(row) for row in matrix)

    def is_zero_matrix(matrix):
        return all(cell == 0 for row in matrix for cell in row)

    def flip(matrix, x, y):
        directions = [(0, 0), (1, 0), (0, 1), (-1, 0), (0, -1)]
        for dx, dy in directions:
            if 0 <= x + dx < len(matrix) and 0 <= y + dy < len(matrix[0]):
                matrix[x + dx][y + dy] ^= 1

    m, n = len(mat), len(mat[0])
    start = to_tuple(mat)
    
    if is_zero_matrix(mat):
        return 0

    queue = deque([(start, 0)])  # Initialize the queue with the starting state and step count
    visited = set([start])         # Keep track of visited states

    while queue:
        current_matrix, steps = queue.popleft()   # Get the current state and step count
        current_matrix = [list(row) for row in current_matrix]  # Convert back to list for manipulation

        for i in range(m):   # Iterate over each cell
            for j in range(n):
                flip(current_matrix, i, j)   # Flip the current cell and its neighbors
                new_state = to_tuple(current_matrix)   # Get the new state as a tuple
                
                if is_zero_matrix(current_matrix):   # Check if we reached the zero matrix
                    return steps + 1
                
                if new_state not in visited:   # If this state has not been visited
                    visited.add(new_state)      # Mark it as visited
                    queue.append((new_state, steps + 1))   # Add it to the queue with incremented step count
                
                flip(current_matrix, i, j)   # Flip back to original state

    return -1   # Return -1 if no solution found
```