#include <iostream>
using namespace std;

int H, W;
char farms[100][100];

void dfs(int x, int y){
  char f = farms[x][y];
  farms[x][y] = '.';
  for (int dy = -1; dy <= 1; dy++) {
    if(dy == -1 || dy == 1){
      int dx = 0;
      int nx = x + dx, ny = y + dy;
      if (0 <= nx && nx < W && 0 <= ny && ny < H && farms[nx][ny] == f){
        dfs(nx, ny);
      }
    }
    if (dy == 0){
      for (int dx = -1; dx <= 1; dx = dx + 2) {
        int nx = x + dx, ny = y + dy;
        if (0 <= nx && nx < W && 0 <= ny && ny < H && farms[nx][ny] == f){
          dfs(nx, ny);
        }
      }
    }
  }
  return ;
}


void solve(){
  int res = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (farms[i][j] != '.'){
        dfs(i, j);
        res++;
      }
    }
  }
  cout << res;
}

int main() {
  cin >> H >> W;
  while (!(H == 0 && W == 0)){
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> farms[i][j];
      }
    }
    solve();
    cin >> H >> W;
  }
  return 0;
}