On a cold Christmas night in 2010, Zagreb was covered in snow. Zdravko decided to leave his castle, cross the road and take a stroll through the Maksimir park. Unfortunately, the idyllic winter evening was interrupted by a monster that was lurking in the nearby bushes. The monster jumped in front of Zdravko, but Zdravko roared a mighty roar which scared the monster away. Unbeknownst to him, a bunch of animals from the nearby zoo were startled by that roar. More precisely, a group of tigers and bulls were so annoyed that they decided to escape the zoo in order to find a nice quiet place to sleep.
During their escape, the animals had to pass through a rectangular area divided
in
Your task is to determine the minimal number of animals that have escaped the Maksimir zoo based on the footprints that were left in the aforementioned rectangular area.
Input
The first line contains two integers
The next
Character T
represents a tiger's footprint, character B
represents a bull's footprint and character *
represents untouched snow.
You can assume that the input data is such that at least one animal entered the rectangular area and that each animal that entered the area has also left the area according to the rules from the task description.
Output
Output the minimal number of animals that have escaped the zoo.
Scoring
Subtask | Score | Constraints |
---|---|---|
Sample Input 1
4 4
TT*T
*TTT
***T
***T
Sample Output 1
1
Sample Input 2
3 5
TTBB*
*T*B*
*TTTT
Sample Output 2
2
Explanation of Sample Output 2

Sample Input 3
7 5
BT***
BTBBB
BTTTB
BBT*B
BBT*B
BBT**
*BBBB
Sample Output 3
3
Comments