#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>

using namespace std;
int ans=0;

void mark(char input[][102], int table[][102], int i, int j);

int main(){
    while (1) {
        int height=0,width=0;
        cin>>height>>width;
        //cout<<height<<width<<endl;
        if (height==0 || width == 0) {
            return 0;
        }

        char input[102][102];
        int table[102][102];
        for (int i=0; i<102; i++) {
            for (int j=0; j<102; j++) {
                input[i][j] = '\0';
                table[i][j] = 0;
            }
        }
        for (int i=1; i<height+1; i++) {
            string line;
            //getline(cin, line);
            cin>>line;
            for (int j=1; j<width+1; j++) {
                input[i][j] = line[j-1];
            }
        }
        for (int i=1; i<height+1; i++ ) {
            for (int j=1; j<width+1; j++) {
                if (table[i][j] == 0) {
                    ans++;
                    mark(input, table, i, j);
                }
            }
        }
        cout<<ans<<endl;
        ans = 0;
    }
}

void mark(char input[][102], int table[][102], int i, int j){
    if (table[i][j] != 0) {
        return;
    }
    char typeOfTree;
    typeOfTree = input[i][j];
    table[i][j] = ans;
    if (typeOfTree == input[i-1][j]) {
        mark(input, table, i-1, j);
    }
    if (typeOfTree == input[i][j-1]) {
        mark(input, table, i, j-1);
    }
    if (typeOfTree == input[i][j+1]) {
        mark(input, table, i, j+1);
    }
    if (typeOfTree == input[i+1][j]) {
        mark(input, table, i+1, j);
    }
}