import std.stdio;
import std.string;

bool[101][101] memo;
string[] s;
int h, w, ans;

void main(){
	while (readf("%d %d\n", &h, &w), h != 0 || w != 0) {
		s = [];
		ans = 0;
		for (int i = 0; i < h; i++) {
			s ~= chomp(readln());
			memo[i] = false;
		}
		for (int y = 0; y < h; y++) {
			for (int x = 0; x < w; x++) {
				if (!memo[y][x]) {
					ans++;
					scan(s[y][x], x, y);
				}
			}
		}
		writeln(ans);
	}
}

void scan(char fruit, int x, int y){
	memo[y][x] = true;
	if(x+1 < w && !memo[y][x+1] && s[y][x+1] == fruit) scan(fruit, x+1, y);
	if(x-1 >= 0 && !memo[y][x-1] && s[y][x-1] == fruit) scan(fruit, x-1, y);
	if(y+1 < h && !memo[y+1][x] && s[y+1][x] == fruit) scan(fruit, x, y+1);
	if(y-1 >= 0 && !memo[y-1][x] && s[y-1][x] == fruit) scan(fruit, x, y-1);
}