9035 - Islands   

Description

A plot '#' represents a land. If two plots are adjacent horizontally, vertically, or diagonally, then they are part of the same island. An island can be quite large and may contain numerous plots. Your job is to determine how many different island are there.

Input

The input file contains one or more maps. Each map begins with a line containing M and N, the number of rows and columns in the map, separated by a single space. If M = N = 0 it signals the end of the input; otherwise 1 <= M <= 100 and 1 <= N <= 100. Following this are M lines of N characters each (not counting the end-of-line characters). Each character corresponds to one plot, and is either '*', representing the sea, or '#', representing the land.

Output

For each map, output the number of distinct islands. Two different lands are part of the same island if they are adjacent horizontally, vertically, or diagonally.

Sample Input  Download

Sample Output  Download

Tags




Discuss