#include<iostream>
#include<string>

using namespace std;

string map[101];
int count=0;
int n,m;

void dfs(char c,int i,int j){
  
    s[i][j] = '.';
    if(i+1 < n && s[i+1][j] == c)
    {
        dfs(c,i+1,j);
    }
    if(i-1 >= 0 && s[i-1][j] == c)
    {
        dfs(c,i-1,j);
    }
    if(j+1 < m && s[i][j+1] == c)
    {
        dfs(c,i,j+1);
    }
    if(j-1 >= 0 && s[i][j-1] == c)
    {
        dfs(c,i,j-1);
    }
}

int main(){

  while(1){

    cin >> n >> m;
     {
       if(n == 0 && m == 0)
	 break;
 
       count = 0;
       rep(i,n) cin >> s[i];
         
       rep(i,n)
	 {
	   rep(j,m)
	     {
	       if(s[i][j] != '.')
		 {
		   dfs(s[i][j],i,j);
		   count++;
		 }
	     }
	 }
         
       cout << count << endl;
     }
  }
}
 
