#include<iostream>
#include<vector>
#include<array>
using namespace std;

void dfs(vector<vector<char>>& farm, 
        vector<vector<bool>>& searched,
        array<int,4>& dy, 
        array<int,4>& dx, 
        int h, 
        int w)
{
    if(searched[h][w]) return;

    searched[h][w] = true;

    for(int i = 0;i < 4;i++){
        if(h + dy[i] < 0 || h + dy[i] >= farm.size()) continue;
        if(w + dx[i] < 0 || w + dx[i] >= farm[0].size()) continue;
        if(searched[h + dy[i]][w + dx[i]]) continue;
        if(farm[h][w] != farm[h + dy[i]][w + dx[i]]) continue;
        dfs(farm, searched, dy, dx, h + dy[i], w + dx[i]);
    }
}

int main(){
    int H,W;
    while(cin >> H >> W, H,W){

        vector<vector<char>> farm(H,vector<char>(W));
        vector<vector<bool>> searched(H,vector<bool>(W,false));
        array<int,4> dy = {1, 0, 0, -1};
        array<int,4> dx = {0, 1, -1, 0};
        int ans = 0;

        for(int i=0;i<H;i++)for(int j=0;j<W;j++){
            cin >> farm[i][j];
        }

        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(searched[i][j]) continue;
                dfs(farm, searched, dy, dx, i, j);
                ans++;
            }
        }

        cout << ans << endl;
    }
}

