#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <cmath>
using namespace std;

#define MAX 1000

int H, W;
char field[MAX][MAX];

int vectorX[4] = {-1,  0, 1, 0};
int vectorY[4] = { 0, -1, 0, 1};

void dfs( int x, int y){
  char kind = field[x][y];
  field[x][y] = 'X';
  for( int i = 0; i < 4; i++ ){
    int dx = x + vectorX[i];
    int dy = y + vectorY[i];
    if( dx >= 0 && dx < W &&
        dy >= 0 && dy < H &&
        field[dx][dy] == kind ){
      dfs(dx,dy);
    }
  }
}

main(){
  while( cin >> H >> W && H && W ){
    int counter = 0;
    for( int i = 0; i < H; i++ ) cin >> field[i];
    for( int i = 0; i < H; i++ ){
      for( int j = 0; j < W; j++ ){
        if( field[i][j] != 'X' ){
          counter++;
          dfs(i,j);
        }
      }
    }
    cout << counter << endl;
  }
}