#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
//#include <>
#include <iostream>
using namespace std;
int n,m;
char input[50][50];
bool judge(int x,int y)
{
    if(0 <= x && x < n && 0 <= y && y < m && input[x][y] != '.')
        return true;
    return false;
}
void dfs(int x,int y,char o)
{
    input[x][y] = '.';
    for(int dx = -1; dx <= 1; dx++){
        for(int dy = -1; dy <= 1; dy++){
            int nx = x + dx,ny = y + dy;
            if(judge(nx,ny) && input[nx][ny] == o)
                dfs(nx,ny,o);
        }
    }
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        if(n == 0 &&m == 0)
            return 0;
        int ans = 0;
        memset(input,0,sizeof(input));
        for(int i = 0; i < n; i++)
            scanf("%s",input[i]);
        printf("\n\n\n");
        for(int i = 0; i < n; i++)
            printf("%s\n",input[i]);
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                if(input[i][j] == '#'){
                    dfs(i,j,'#');
                    ans++;
                }
                if(input[i][j] == '*'){
                    dfs(i,j,'*');
                    ans++;
                }
                if(input[i][j] == '@'){
                    dfs(i,j,'@');
                    ans++;
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}