#include <queue>
#include <stdio.h>
#include <algorithm>
using namespace std;

int dx[] = {0,1,0,-1},
dy[] = {-1, 0, 1, 0};

typedef pair<int,int> P;

int main(void)
{
	int N,M;

	while(1){
	scanf("%d %d", &N, &M);
	if(N == M && N == 0)
		break;

	char **s = new char *[N];

	for(int i = 0; i < N; i++){
		s[i] = new char [M+1];


	}
	for(int i = 0; i < N; i++)
		scanf("%s", s[i]);

	int count = 0;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < M; j++){
			if(s[i][j] != 'a'){
				char a = s[i][j];
				s[i][j] = 'a';
				count++;
				queue<P> q;
				q.push(P(j,i));

				while(q.size()){
					P p = q.front();	q.pop();

					for(int k = 0; k < 4; k++){
						int nx = dx[k] + p.first, ny = dy[k] + p.second;

						if(ny > -1 && nx > -1 && ny < N && nx < M && s[ny][nx] == a){
							q.push(P(nx,ny));
							s[ny][nx] = 'a';
						}
					}
				}
			}
		}
	}
	printf("%d\n",count);
	}
	return 0;
}