#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int maxn = 100;

int a,b;
int count_a=0;
char MAP[100][100];
int MOVE[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
void dfs(int x,int y,char z)
{
    MAP[x][y]='.';
    for(int i=0;i<4;i++)
    {
        int nx=x+MOVE[i][0];
        int ny=y+MOVE[i][1];
        if(nx>=0&&nx<a&&ny>=0&&ny<b&&MAP[nx][ny]==z)
        {
            dfs(nx,ny,z);
        }
    }
}
int main()
{
    while(cin>>a>>b){
        if(a==0&&b==0){return 0;}
        for(int i=0;i<a;i++)
        {
            for(int j=0;j<b;j++)
            {
                cin>>MAP[i][j];
            }
        }
        for(int i=0;i<a;i++){
            for(int j=0;j<b;j++){
                if(MAP[i][j]!='.'){dfs(i,j,MAP[i][j]);count_a++;}
            }
        }
        cout<<count_a<<endl;
    }
    return 0;
}

