#include <iostream>
#include <vector>

using namespace std;

void fill(vector<vector<char> >& vec,int i, int j, char c){
    if(vec[i][j] == c) {
        vec[i][j] = '^';
    } else {
        return;
    }
    fill(vec,i+1,j,c);
    fill(vec,i-1,j,c);
    fill(vec,i,j+1,c);
    fill(vec,i,j-1,c);
}

int main(){
    while (1) {
        int h,w;
        cin >> h;
        cin >> w;
        if(!h&&!w) break;
        vector< vector<char> > vec(h+2,vector<char>(w+2));
        for(int i = 0; i <= h+1; ++i){
            for (int j = 0; j <= w+1; j++) {
                if(i == 0 || j == 0 || i == h+1 || j == w+1)
                    vec[i][j] = '^';
                else
                    cin >> vec[i][j];
            }
        }
        int persons = 0;
        for(int i = 1; i <= h; ++i){
            for (int j = 1; j <= w; j++) {
                char c = vec[i][j];
                if(c == '^')
                    continue;
                else {
                    persons++;
                    fill(vec,i,j,c);
                }
            }
        }
        cout << persons << endl;
    }
    return 0;
}