#include <iostream>
#include <string.h>

using namespace std;

const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
char field[102][102] = {};

int dfs(int x,int y)
{
	if(field[y][x] == 0)
		return 0;
	char c = field[y][x];
	field[y][x] = 0;
	for(int i=0;i<4;++i){
		if(c == field[y+dy[i]][x+dx[i]])
			dfs(x+dx[i],y+dy[i]);
	}
	return 1;
}

int main(void)
{
	while(1){
		int hei,wei;
		cin >> hei >> wei;
		if(hei == 0 && wei == 0)
			return 0;

		for(int y=1;y<=hei;++y){
			char str[101];
			cin >> str;
			for(int x=1;x<=wei;++x){
				field[y][x] = str[x-1];
			}
		}

		int ans=0;
		for(int y=1;y<=hei;++y){
			for(int x=1;x<=wei;++x){
				ans+=dfs(x,y);
			}
		}
		cout << ans << endl;
	}
	return 0;
}