// https://onlinejudge.u-aizu.ac.jp/problems/0118
// Property Distribution
// 输出分割成几片

#include <iostream>
#include <queue>
#include <map>

using namespace std;

char m[102][102];
typedef pair<int, int> pii;
pii dir[4] = {pii(0, 1), pii(0, -1), pii(-1, 0), pii(1, 0)};

int M, N;   // 行、列

// dfs
void kill(int x, int y)
{
    char t = m[y][x];
    queue<pii> q;
    q.push(pii(x, y));
    m[y][x] = 0;
    while (!q.empty())
    {
        pii cur = q.front();
        q.pop();
        for (int i = 0; i < 4; ++i)
        {
            pii tmp = pii(cur.first + dir[i].first, cur.second + dir[i].second);
            if (tmp.first >= 0 && tmp.second >= 0
                && tmp.first < N && tmp.second < M
                && m[tmp.second][tmp.first] == t)
            {
                m[tmp.second][tmp.first] = 0;
                q.push(tmp);
            }
        }
    }
}

int main()
{
    while (cin >> M >> N && M + N != 0)
    {
        for (int i = 0; i < M; ++i)
            cin >> m[i];
        int ans = 0;
        for (int i = 0; i < M; ++i)
            for (int j = 0; j < N; ++j)
                if (m[i][j] != 0)
                    kill(j, i), ans++;

        cout << ans << endl;
    }
    return 0;
}
