#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;


int H,W,hatake[110][110],memo[110][110],wakemae;
std::string field[110];

int search(int h,int w){
  if(memo[h][w]==1) return 0;
  if(memo[h][w]==0)memo[h][w]=1;
  int k[4]={1,0,-1,0},vi=0;
  for(int i=0;i<4;i++){
    if(memo[h+k[i]][w+k[3-i]]==0&&hatake[h][w]==hatake[h+k[i]][w+k[3-i]]){
	search(h+k[i],w+k[3-i]);
	vi++;
    } else {
      vi++;
    }
  }
  if(vi==4){return 1;}
}

int main(){
  while(1){
    cin>>H;
    cin>>W;
    if(H==0&&W==0)break;
    for(int i=0;i<H;i++){
      cin>>field[i];
      for(int j=0;j<W;j++){
	if(field[i][j]=='@')hatake[i+1][j+1]=1;
	if(field[i][j]=='*')hatake[i+1][j+1]=2;
	if(field[i][j]=='#')hatake[i+1][j+1]=3;
      }
    }
    int count=0;
    for(int i=1;i<=H;i++){
      for(int j=1;j<=W;j++){
	int sssss=search(i,j);
	count=count+sssss;
      }
    }
    cout<<count<<endl;
  }
}