John runs a furniture workshop, and his wealthy clients often order suites made from precious hardwood. To fill a batch of orders he must cut one rectangular hardwood board, m × n feet in size, into several pieces. He has already drawn the outline of every piece on the board and plans to use his circular saw.
The saw has one limitation: it can only make a straight cut that begins at an edge of the board — or at an edge freshly exposed after a part has been removed — and runs in a straight line. A cut may never pass through the interior of a marked piece. After a part is separated, John may take it away, begin new cuts from the newly exposed edges, and rearrange the separated parts however he likes.
Even so, some pieces cannot be separated with the circular saw alone. For example, two pieces may interlock, or one piece may be notched into another so that the last side needed to free it can only be reached from inside the wood; such pieces must later be finished with a fret-saw. To minimise the fret-saw work, John wants to split the board into as many parts as possible with the circular saw. Determine that maximum number of parts.
The first line contains two integers m and n (1 ≤ m, n ≤ 20) — the height and width of the board in feet.
Each of the next m lines contains n characters describing the marking of the board. Every unit square is marked with an English letter or a digit; unit squares that belong to the same piece carry the same character, and the squares of each piece form a single edge-connected region. Uppercase and lowercase letters are considered different.
Print a single integer — the maximum number of parts into which John can cut the board using only the circular saw.
In the board shown below, pieces C and D cannot be separated from each other, and neither can pieces E and Z.
