eolymp
bolt
Try our new interface for solving problems
Problems

Chocolate

Chocolate

Marichka and Zenik have a rectangular tile of delicious Ukrainian chocolate. The tile consists of the same squares, each of which can be either black or white.

Marichka will draw an arbitrary (possibly zero) number of full horizontal (from left to right) tile sections, while Zenik will draw an arbitrary (possibly zero) number of full vertical (top to bottom) sections. Note that cuts can only be made between the squares of the tile, and Zenik and Marichka can make a different number of cuts. After all the cuts, the tile will fall into a certain number of rectangular pieces, which our heroes will divide among themselves in a certain way.

Since Zenik is very fond of dark chocolate, he wants after all cuts the number of whole pieces, which consist exclusively of black squares, be as large as possible. Marichka wants to make the same amount as small as possible. Note that the heroes are not interested in what size the pieces will be: the main thing is their number.

In order to be honest, Andrei will separately and independently ask Marichka and Zenik in which exact places to cut, and then he will make these cuts.

Write a program that, according to the given tile size, as well as the type of each unit square, will determine how many pieces are formed after all cuts, consisting solely of black squares, under the condition of optimal actions of both heroes.

Input

First line contains two integers n and m (2n1000, 2m1000): the height and the width of the tile respectively. Next given n lines of m characters each, which indicate the type of corresponding unit chocolate bar. Symbol B means a black square, symbol W means white.

Output

Print the number of pieces that will consist exclusively of squares of dark chocolate.

Time limit 1 second
Memory limit 128 MiB
Input example #1
3 4
BWBB
BBBW
BBBW
Output example #1
2
Source 2015 XXVIII All-Ukrainian Olympiad in Informatics