#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

char m[100][100];
pair<int, int> a[4] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
int h, w;
bool used[100][100];

void dfs(int y, int x, char c)
{
    used[y][x] = 1;
    rep(i, 4)
    {
        int ny = y + a[i].second, nx = x + a[i].first;
        if (used[ny][nx] || m[ny][nx] != c || !((0 <= ny && ny < h) && (0 <= nx && nx < w)))
            continue;
        dfs(ny, nx, c);
    }
}

int main()
{
    while (cin >> h >> w, h)
    {
        rep(i, h) rep(j, w) cin >> m[i][j];
        rep(i, h) rep(j, w) used[i][j] = 0;

        int cnt = 0;

        rep(i, h)
        {
            rep(j, w)
            {
                if (!used[i][j])
                {
                    cnt++;
                    dfs(i, j, m[i][j]);
                }
            }
        }
        OP(cnt);
    }

    return 0;
}
