/*****include*****/
#include <iostream>
#include <queue>
/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/
char **field;
bool **visited;
queue <int>task_x;
queue <int>task_y;
int height,width;
/*****その他関数置き場*****/
void bfs(int x,int y,char state){
	int nx,ny;
	int x_next,y_next;
	int x_table[] = {0,-1,0,1};
	int y_table[] = {1,0,-1,0};
	task_x.push(x);task_y.push(y);
	visited[y][x] = true;
	while(!task_x.empty() && !task_y.empty()){
		nx = task_x.front();task_x.pop();
		ny = task_y.front();task_y.pop();
		for(int i=0;i<4;i++){
			x_next = nx + x_table[i];
			y_next = ny + y_table[i];
			if((x_next >= 0 && x_next < width) &&  (y_next >= 0 && y_next < height))
				if(!visited[y_next][x_next] && field[y_next][x_next] == state){
					task_x.push(x_next);
					task_y.push(y_next);
					visited[y_next][x_next] = true;
				}
		}
	}
}
/*****main関数*****/
int main(){
	/*****変数置き場*****/
	int x,y;
	int counter;
	/*****処理部*****/
	while(1){
		counter = 0;
		cin >> height >> width;
		if((height==0 && width==0) || cin.eof())	break;
		field = new char* [height];
		visited = new bool* [height];
		for(int i=0;i<height;i++){
			field[i] = new char [width];
			visited[i] = new bool [width];
		}
		for(int i=0;i<height;i++)
			for(int j=0;j<height;j++){
				cin >> field[i][j];
				visited[i][j] = false;
			}
		x = 0;
		y = 0;
		for(y=0;y<height;y++)
			for(x=0;x<width;x++)
				if(!visited[y][x]/*field[y][x] != '0'*/){
					bfs(x,y,field[y][x]);
					counter++;
				}
		cout << counter << endl;
	}
	
	/*****処理終了後*****/
	return 0;
}