The relief of an area near Alone Hill was measured using an old machine which might be inaccurate.
The area has a rectangular form, and it was split into a rectangular grid containing n rows and m columns of equal squares.
The results are given as a String heights, where the j-th character of the i-th element is '1' (one) if the height of the point at the center of the square at row i, column j is greater than some constant value, and '0' (zero) otherwise.
heights contains exactly n elements, each element of which contains exactly m characters.
A cell is a neighbour of another cell if they share the side.
The measured area has one special property: if point A is the center of some cell and point B is the center of the neighbour cell and point A is closer to the hill peak than point B, then
the height of A is greater or equal than the height of B.
Distance is measured using the euclidian distance along the horizontal plane. In other words, the distance between point (xa,ya) and point (xb,yb) is equal to sqrt((xa-xb)^2+(ya-yb)^2). It is known that one of the given measurements was taken at the peak of the hill, i.e., the hill coincides with the center of one of the squares.
Using that property, you can tell whether or not the given results might be accurate. For example, the relief map on the left might be accurate while the one on the right is definitely not:
Return the minimal number of characters you must replace in heights to make the results possibly accurate. If it is already possible that the results are accurate, return 0.