#include<iostream>
#include<string>
using namespace std;
int h,w,ans;
string m[150];
void solve(int y,int x){
  char c = m[y][x];
  if(m[y][x] == '0') return;
  m[y][x] = '0';
  if(y+1 < h && m[y+1][x] == c) solve(y+1,x);
  if(x+1 < w && m[y][x+1] == c) solve(y,x+1);
  if(y-1 >= 0 && m[y-1][x] == c) solve(y-1,x);
  if(x-1 >= 0 && m[y][x-1] == c) solve(y,x-1);
}
int main(void){
  for(;;){
    cin >> h >> w;
    if(!h && !w) break;
    ans = 0;
    for(int i = 0;i < h; i++) cin >> m[i];
    for(int i = 0;i < h; i++){
      for(int j = 0; j < w; j++){
	if(m[i][j] != '0'){
	  solve(i,j);
	  ans++;
	}
      }
    }
    cout << ans << endl;
  }
}
