#include <iostream>
#include <cstring>
#define bswap(a,b) a^=b^=a^=b
#define _for(i,a,b) for(int i = (a); i < b; ++i)
#define _rep(i,a,b) for(int i = (a); i <= b; ++i)
#define met(a) memset(a,0,sizeof(a))
#define _met(a) memset(a,-1,sizeof(a))

using namespace std;
const int maxn = 20+5;
char rec[maxn][maxn];
bool visited[maxn][maxn] = {0};
int dx[] = {1, 0, 0, -1};
int dy[] = {0, -1, 1, 0};
char a;
//pair<int, int> p;
int ans = 0;
int w, h;
void init()
{
    met(visited);
    ans = 0;
}
void dfs(int x, int y)
{
    //cout<<x<<" "<<y<<endl;
    visited[x][y] = true;
    _for(i,0,4){
        int nowx = x + dx[i];
        int nowy = y + dy[i];
        //cout<<nowx<<" "<<nowy<<endl;
        if(0 <= nowx && nowx < h && 0 <= nowy && nowy < w &&
           rec[nowx][nowy] == a && !visited[nowx][nowy]){
            //ans++;
            dfs(nowx, nowy);
        }
    }
}
int main()
{

    cin>>w>>h;
    while(w&&h)
    {
        init();
        _for(i,0,h) _for(j,0,w) cin>>rec[i][j];
        _for(i,0,h) _for(j,0,w){
            if(!visited[i][j]) {
                a = rec[i][j];
                ans++;
                dfs(i,j);
            }
        }
        cout<<ans;
        cin>>w>>h;
    }

    return 0;
}

