#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void fill(int y, int x, char c, vector<vector<char> > &f){
	if(f[y][x] != c) return;
	f[y][x] = '.';
	for(int i=0; i<4; i++){
		fill(y+dy[i], x+dx[i], c, f);
	}
}

int main(){
	while(1){
		int h,w;
		cin >> h >> w;
		if(h==0) break;
		
		vector<vector<char> > field(h+2, vector<char>(w+2, '.'));
		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++){
				cin >> field[i][j];
			}
		}
		
		int ans = 0;
		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++){
				if(field[i][j] != '.'){
					ans++;
					fill(i, j, field[i][j], field);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

