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

int h,w;
string s[1000];
char k;

void solve(int x,int y){

  if(s[x][y] != k) return;
  s[x][y] = '.';

  if(x+1 < h) solve(x+1,y);
  if(y+1 < w) solve(x,y+1);
  if(x-1 >= 0) solve(x-1,y);
  if(y-1 >= 0) solve(x,y-1);

}

int main(){

  while(true){
    cin >> h >> w;
    if(!(h+w)) break;

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

    int ans = 0;

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(s[i][j] != '.'){
	  k = s[i][j];
	  solve(i,j);
	  ans++;
	}
      }
    }

    cout << ans << endl;
  }
}