A single fence is defined by a pair of side-adjacent cells. This means that fences can only be internal. So any fence between a cell and the outside world should not be counted, right?
Consider this example with rows = 2, cols = 4
Cell (1,5) is part of the outside world. We would not need a fence wall between the cell (1, 4) and (1, 5), right?