Ahistogram is a simple rectilinear polygon (i.e. the interior angle at each vertex is either ° or °) that has a horizontal edge seeing every point inside (i.e. the interior or the boundary of) . Here, we say that an edge sees a point if there is a vertical segment connecting to that is lying inside .
Let be a histogram with vertices, and consider a decomposition of into rectangles whose sides are vertical or horizontal. The vertices of the rectangles need not all be vertices of : it is allowed to introduce additional vertices, on the boundary of and/or in its interior. The stabbing number of a horizontal or vertical segment inside with respect to such a decomposition is the number of rectangles from whose interior (not just their boundaries) are intersected by . The stabbing number of is the maximum stabbing number of any horizontal or vertical segment that lies inside . The goal is to compute a decomposition with the minimum stabbing number.
The first line of the input contains two positive integers and () denoting the number of rows and the number of columns of the table illustrating the histogram, respectively. The next lines, each contains exactly n characters. *
s denote the boundary of the histogram. The rest is filled with dots (.
). Each edge of the histogram contains at least three *
s. You can assume the given histogram has at least four and at most 16 edges, and edges do not overlap, intersect or touch each other; i.e. each *
is adjacent to exactly two other *
characters.
Print the stabbing number of the given histogram in one line.