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

string s[1000];
int n,m,memo[1000][1000],x,y;

int solve(int i, int j){

  if(s[i][j] != s[x][y]) return 0;
  if(memo[i][j] > 0) return memo[i][j];
  memo[i][j] = 1;

  if(i + 1 < n && s[i + 1][j] == s[x][y]) solve(i + 1,j);
  if(j + 1 < m && s[i][j + 1] == s[x][y]) solve(i,j + 1);
  if(i - 1 > -1 && s[i - 1][j] == s[x][y]) solve(i - 1,j);
  if(j - 1 > -1 && s[i][j - 1] == s[x][y]) solve(i,j - 1);
  
  return 0;
}

 
int main(){

  while(true){
    cin >> n >> m;
    if(!n && !m) break;
    memset(memo,0,sizeof(memo));
    int count = 0;

    for(int i=0;i<m;i++) cin >> s[i];

    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
	if(memo[i][j] != 1){
	  x = i;
	  y = j;
	  solve(i,j);
	  count++;
	}
      }
    }

    cout << count << endl;
  }
}