Vasylko is a beginning programmer. His latest idea was to create a graphic editor for black and white images. Unfortunately, he only managed to implement one tool — the fill operation.
The image in the editor is represented as a rectangular table of N \times M cells; each cell is either black or white. Two cells are considered adjacent if they share a side. A region is defined as a maximal subset of cells of the same color such that each cell in the region can be reached from any other by moving through adjacent cells in the same region.
The fill tool works as follows: the user selects any cell in the table, and then the entire region containing the selected cell is recolored to the opposite color.
Vasylko now wants to learn how to erase images using his editor. An image is considered erased if it is either entirely black or entirely white. Determine the minimum number of fills required to erase the given image.
Two natural numbers , (1 \leq N \leq 100, 1 \leq M \leq 100) are given — the number of rows and columns in the table representing the image. The next lines each contain characters. In the -th row and -th column, a indicates a white cell and a indicates a black cell.
Output a single number — the minimum number of fills required to erase the given image.
Example 1