Competitions
Пошук в ширину
Cell removal
From a rectangular sheet of paper (m rows, n columns) some cells are removed. In how many pieces the sheet will be fall apart? Two cells do not fall apart if they have a common side.
Input
The first row contains the numbers m and n (1 ≤ m, n ≤ 100). Each of the following m lines contains n symbols. If the cell is not cut, it is represented with the # sign, if it is cut, it is given with a point.
Output
Print the number of parts of the sheet.
Input example #1
4 8 #.##.#.# ......## #.###.## ##.##.##
Output example #1
6