#include<iostream>
#include<cstdio>
using namespace std;
const int MAX = 101;

char a[MAX][MAX];
int mt[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
int n, m, sum=0;

void dfs(int x, int y, const char ch){
	if (x < 0 || x >= n || y < 0 || y >= m || a[x][y] != ch || a[x][y] == '0'){
		return ;
	}
	a[x][y] = '0';
	for (int i = 0; i < 4; i++){
		int nx = x + mt[i][0];
		int ny = y + mt[i][1];
		dfs(nx, ny, ch);
	}
}
	
void solve(){
	for (int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if (a[i][j] != '0'){
				dfs(i, j, a[i][j]);
				sum++;
			}
		}
	}
}

int main(){
	
	while(scanf("%d %d", &n, &m) == 2 && n){
	sum = 0;	
	
	for (int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin >> a[i][j];
		}
	}
	
	solve();
	cout << sum << endl;
	}
	return 0;
}



