#include <cstdio>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#define min(a,b)    (((a) < (b)) ? (a) : (b))
#define max(a,b)    (((a) > (b)) ? (a) : (b))
#define abs(x)    ((x) < 0 ? -(x) : (x))
#define INF 0x3f3f3f3f
#define delta 0.85
#define eps 1e-3
#define PI 3.14159265358979323846
#define MAX_N 105
using namespace std;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
int H, W;
char mp[MAX_N][MAX_N];

bool judge(int x, int y, char f){
	return x >= 0 && x < H && y >= 0 && y < W && mp[x][y] == f;
}

void dfs(int x, int y){
	char tmp = 'u';
	swap(tmp, mp[x][y]);
	for(int i = 0; i < 4; i++){
		int nx = x + dx[i], ny = y + dy[i];
		if(judge(nx, ny, tmp)) dfs(nx, ny);
	}
	return;
}

int main(){
	while(~scanf("%d%d", &H, &W) && H){
		for(int i = 0; i < H; i++) scanf("%s", mp + i);
		int res = 0;
		for(int x = 0; x < H; x++){
			for(int y = 0; y < W; y++){
				if(mp[x][y] != 'u'){
					dfs(x, y);
					++res;
				}
			}
		}
		printf("%d\n", res);
	}
	return 0;
}
