#include<iostream>
using namespace std;

char field[100][100];
bool chack[100][100];
int H,W;

void move(int i, int j){
    chack[i][j] = true;
    if(i+1 < H && !chack[i+1][j] && field[i][j] == field[i+1][j]) move(i+1,j);
    if(i-1 >= 0&& !chack[i-1][j] && field[i][j] == field[i-1][j]) move(i-1,j);
    if(j+1 < W && !chack[i][j+1] && field[i][j] == field[i][j+1]) move(i,j+1);
    if(j-1 >= 0&& !chack[i][j-1] && field[i][j] == field[i][j-1]) move(i,j-1);
}

int main (void){
    while(1){
        int count = 0;
        cin >> H >> W;
        if(H==0&&W==0) break;
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                cin >> field[i][j];
                chack[i][j] = false;
            }
        }
        for(int i=0; i<H; i++)
            for(int j=0; j<W; j++)
                if(chack[i][j]==false){
                    count++;
                    move(i,j);
                }
        cout << count << endl;
    }
}

