#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
#define scai(x) scanf("%d", &x)
#define scac(x) scanf("%c", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define pri(x) printf("%d", x)
#define prc(x) printf("%c", x)
#define pri2(x,y) printf("%d %d", x, y);
#define prif(x) printf("%lf", x)
#define prif2(x, y) printf("%lf %lf", x, y)
#define mset(x, y) memset(x, y, sizeof(x))
#define fori(i, x, y) for(int i = x; i < y; i++)
#define pii pair<int, int>
#define pic pair<int, char>
#define pdd pair<double, double>
typedef long long ll;
const int H = 105;
const int W = 105;
char field[H][W];

int m, n;

int a[4] = {1, 0, -1, 0};
int b[4] = {0, 1, 0, -1};

void dfs(int x, int y, char c)
{
    field[x][y] = '$';
    for(int i = 0; i < 4; i++)
    {
        int x1 = x + a[i];
        int y1 = y + b[i];
        if(0 <= x1 && x1 < m && 0 <= y1 && y1 < n && field[x1][y1] == c)
        {

            dfs(x1, y1, c);
        }
    }
    return ;
}
int main()
{
    while(~scanf("%d %d", &m, &n) && m && n)
    {

        int ans = 0;
        mset(field, '$');
        fori (i, 0, m){
            getchar();
            fori (j, 0, n)
            {
                scac(field[i][j]);
            }
        }

        fori (i, 0, m)
            fori (j, 0, n)
            {
                if(field[i][j] != '$')
                    {
                        ans++;
                        dfs(i, j, field[i][j]);
                    }
            }
            cout << ans << endl;
    }
}
