#include <iostream>
#include <string>
using namespace std;

void move(string area[], int i, int j, char ch, int h, int w){
	area[i][j] = '.';
	if(i - 1 >= 0 && area[i-1][j] == ch) move(area, i - 1, j, ch, h, w);
	if(i + 1 < h && area[i+1][j] == ch) move(area, i + 1, j, ch, h, w);
	if(j - 1 >= 0 && area[i][j-1] == ch) move(area, i, j - 1, ch, h, w);
	if(j + 1 < w && area[i][j+1] == ch) move(area, i, j + 1, ch, h, w);
}

int main(){
	const int hmax = 100;
	int h, w;
	string area[hmax];
	while(cin >> h >> w){
		getline(cin, area[0]);
		int count = 0;
		if(h == 0 && w == 0) break;
		for(int i = 0; i < h; i++){
			getline(cin, area[i]);
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(area[i][j] != '.'){
					count++;
					move(area, i, j, area[i][j], h, w);
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}