Problem 1133. Go-style solver

Consider a variation of the game Go where one player has gone ahead and placed several pieces all at once. Assuming that the second player also gets to place several pieces at once, find the minimum number of pieces that the second player needs to place in order to capture all of the pieces placed by the first player.

The first player's pieces will be represented by ones and the empty spaces will be represented by zeros.

To capture a piece, it and every piece that touches it need to be surrounded horizontally and vertically. The board won't necessarily be square. If the first player filled the entire board, return 0.