Transform to Chessboard

Transform an n×n binary matrix into an alternating chessboard pattern using only row-wise and column-wise swaps. Return the minimum number of swaps, or -1 if impossible. A valid board requires each row and column to have exactly half 0s and half 1s.

Examples
Input: [[0,1],[1,0]]
Output: 0
Hints

Transform to Chessboard

Transform an n×n binary matrix into an alternating chessboard pattern using only row-wise and column-wise swaps. Return the minimum number of swaps, or -1 if impossible. A valid board requires each row and column to have exactly half 0s and half 1s.