#include <iostream>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;
struct stk {
	int y, x;
	stk(int y, int x) : y(y), x(x) { }
};


void chil(int y, int x, int h, int w, vector<string>& bd){
int	dx[]={1,-1,0,0};
int	dy[]={0,0,1,-1};
int cnq=0;
	char mrk = bd[y][x];
	queue< stk > que;
	que.push(stk(y,x));
	while(!que.empty()){
		stk cr = que.front();
		que.pop();
		if(bd[cr.y][cr.x] == mrk ) bd[cr.y][cr.x] = 'C';
		rep(i,4){
			if(cr.y+dy[i] < 0 || cr.y+dy[i] >= h) continue;
			if(cr.x+dx[i] < 0 || cr.x+dx[i] >= w) continue;
			if(bd[cr.y+dy[i]][cr.x+dx[i]] == mrk ){
				que.push(stk(cr.y+dy[i], cr.x+dx[i]));
			}
		}
	}
//	cout << cnq  << endl;
}


int main(void){

int h,w;
	
	while( cin >> h >> w){
		if(h==0 && w==0 || cin.eof()) break;
		vector< string > bd(h+1);
		rep(i,h)  cin >> bd[i];
		int cnt = 0;
		rep(i,h) rep(j,w){
			if(bd[i][j]=='#' || bd[i][j]=='*' || bd[i][j]=='@'){
				cnt++;
				chil(i, j, h, w, bd);
			}
		}
		cout << cnt << endl;
//		rep(i,h){ rep(j,w) cout << bd[i][j]; cout << endl; }
	}
	return 0;
	
}