#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;
#define ll long long
#define pb push_back

// 前に&をつけるとvectorの参照渡しになる
void solve(int x, int y, vector<vector<char> >& tile, int H, int W, vector<vector<bool> >& flag) {
    // cout << "(" << y << ","<< x << endl;
    char flutes = tile[y][x];
    flag[y][x] = false;
    
    if (y + 1 < H) {
        if (tile[y + 1][x] == flutes && flag[y + 1][x]) {
            solve(x, y + 1, tile, H, W, flag);
        }
    }
    if (y - 1 >= 0) {
        if (tile[y - 1][x] == flutes && flag[y - 1][x]) {
            solve(x, y - 1, tile, H, W, flag);
        }
    }
    if (x + 1 < W) {
        if (tile[y][x + 1] == flutes && flag[y][x + 1]) {
            solve(x + 1, y, tile, H, W, flag);
        }
    }
    if (x - 1 >= 0) {
        if (tile[y][x - 1] == flutes && flag[y][x - 1]) {
            solve(x - 1, y, tile, H, W, flag);
        }
    }
    return;
}

int main() {

    int H, W;
    while(true) {
        cin  >> H >> W;
        if (W==0 && H == 0) break;
        vector<vector<char> > tile(H, vector<char>(W));
        vector<vector<bool> > flag(H, vector<bool>(W, true));
        int count = 0;

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

        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (flag[i][j]) {
                    count++;
                    // cout << "f : " << i << "," << j << endl;
                    solve(j, i, tile, H, W, flag);
                }
            }
        }

        cout << count << endl;
    }

}

