#include<iostream>
#include<queue>
#include<vector>
#define repn(i,m,n) for(i = m;i < n;i++)
#define rep(i,n) for(i = 0;i < n;i++)
#define F first
#define S second

//#define DEBUG DEBUG

using namespace std;

typedef pair<int,int> P;

char str[102];
int data[102][102];
bool done[102][102];
int H,W;
//区分けする関数
int separate(int i,int j);

int main(){
	int i,j;
	int sum[200] = {0},scor = 0;
	while(1){
		cin >> H >> W;
		if(H == 0 && W == 0)
			break;
		rep(i,H+2){
			rep(j,W+2){
				data[i][j] = 0;
				done[i][j] = false;
			}
		}
		repn(i,1,H+1){
			cin >> str;
			repn(j,1,W+1){
				switch(str[j-1]){
				case '#':
					data[i][j] = 1;
					break;
				case '*':
					data[i][j] = 2;
					break;
				case '@':
					data[i][j] = 3;
					break;
				}
			}
		}
		repn(i,1,H+1){
			repn(j,1,W+1){
				sum[scor] += separate(i,j);
			}
		}
		scor++;
	}
	rep(i,scor)
		cout << sum[i] << endl;	
	return 0;
}
int separate(int i,int j){
	queue<P> que;
	P now;

	que.push(P(i,j));
	if(done[i][j])
		return 0;
	while(!que.empty()){
		now = que.front();
		que.pop();
		if(done[now.F][now.S])
			continue;
		done[now.F][now.S] = true;
		//4辺を調べる
		if(data[now.F+1][now.S] == data[now.F][now.S]){
			if(done[now.F+1][now.S] == false){
				que.push(P(now.F+1,now.S));
			}
		}
		if(data[now.F-1][now.S] == data[now.F][now.S]){
			if(done[now.F-1][now.S] == false){
				que.push(P(now.F-1,now.S));
			}
		}
		if(data[now.F][now.S+1] == data[now.F][now.S]){
			if(done[now.F][now.S+1] == false){
				que.push(P(now.F,now.S+1));
			}
		}
		if(data[now.F][now.S-1] == data[now.F][now.S]){
			if(done[now.F][now.S-1] == false){
				que.push(P(now.F,now.S-1));
			}
		}
	}
	return 1;
}