#include <iostream>
using namespace std;
#define RINGO '@'
#define KAKI '#'
#define MIKAN '*'
#define DONE '.'
int w,h;
char area[1000][1000];

int di[]={1,-1,0,0}, dj[]={0,0,1,-1};
void rec(int i, int j, char c){
  if( i<0 || j<0 )
    return;
  if( i>=h || j>=w )
    return;
  if( area[i][j] != c )
    return;

  area[i][j] = DONE;

  for( int d=0;d<4;d++ )
    rec(i+di[d], j+dj[d], c);
}

int main(){
  while( cin >> h >> w, w ){
    for( int i=0;i<h;i++ )
      for( int j=0;j<w;j++ )
	cin >> area[i][j];

    int ans=0;
    for( int i=0;i<h;i++ ){
      for( int j=0;j<w;j++ ){
	if( area[i][j]== DONE )
	  continue;
	ans++;
	rec(i, j, area[i][j]);
      }
    }
    cout << ans << endl;
  }

  return 0;
}