A survey of a tidal flat is recorded as an R-by-C binary grid: 1 marks a land cell and 0 marks a water cell. Each cell is a unit square. A conservation team wants to fence off every exposed edge of land: an edge of a land cell must be fenced if the cell on the other side of that edge is water, or if that edge lies on the outer border of the grid.
Compute the total length of fencing needed, i.e. the total number of exposed land edges over the whole grid. (Cells are considered adjacent only up, down, left, or right, not diagonally.)
Input format
Line 1: two integers R and C.
Next R lines: each contains C space-separated integers, each 0 or 1.
Output format
A single integer: the total exposed edge length of all land cells.
Constraints
- 1 <= R, C <= 200
- Each cell is 0 or 1.