#include<iostream>
#include<string>
using namespace std;
int field[102][102] = {0};
int d[4][2] = {{0,1},{1,0},{-1,0},{0,-1}};
void dfs(int x, int y, int n);
int main(){
  int h,w;
  while(cin >>h>>w,h||w){
    int ans = 0;
    string s;
    for(int i=0; i<102; i++){for(int j=0; j<102; j++){field[i][j] = 0;}}
    for(int i=0; i<h; i++){
      cin >>s;
      for(int j=0; j<w; j++){
	if(s[j] == '#'){field[i+1][j+1] = 1;}
	if(s[j] == '*'){field[i+1][j+1] = 2;}
	if(s[j] == '@'){field[i+1][j+1] = 3;}
      }
    }
    for(int i=0; i<h+2; i++){
      for(int j=0; j<w+2; j++){
	if(field[i][j]!=0){
	  dfs(i,j,field[i][j]);
	  ans++;
	}
      }
    }
    cout <<ans<<endl;
  }
  return 0;
}
void dfs(int x, int y, int n){
  field[x][y] = 0;
  for(int i=0; i<4; i++){
    if(field[x+d[i][0]][y+d[i][1]] == n){dfs(x+d[i][0],y+d[i][1],n);}
  }
}