#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int H,W;

void saiki(vector< vector<char> >& map,int i,int j,char c){

	map[i][j] = ' ';
	for (int dx=-1;dx<=1;dx++){
	    if(j+dx >= 0 && j+dx<W){
		if(map[i][j+dx] == c){
		    saiki(map,i,j+dx,c);
		}
	    }
	}
	for (int dy=-1;dy<=1;dy++){
	    if(i+dy >= 0 && i+dy<H){
		if(map[i+dy][j] == c){
		    saiki(map,i+dy,j,c);
		}
	    }
	}
}


int main(){

    bool flag = true;
    char temp;
    vector< vector<char> > map;
    while(flag){
	int count = 0;
	cin >> H >> W;
	if(H==0&&W==0)flag = false;
	for(int i=0;i<H;i++){
	    map.push_back( vector<char>()  );
	    for(int j=0;j<W;j++){
		cin >> temp;
		map[i].push_back(temp);
	    }
	}

	char c;
	for(int i=0;i<H;i++){
	    for(int j=0;j<W;j++){
		c = map[i][j];
		if(c != ' '){
		    count++;
		    saiki(map,i,j,c);
		}
	    }
	}
	    cout << count << endl;
	    map.clear();
    }
	return 0;
    }