#include<iostream>
#include<string>
using namespace std;
#define MAX_N 100
void makemap(int h);
void seach();
void setblank(int x, int y, char c);
int h, w, ans;
string str[MAX_N];

int main(){
    while(cin >>h >>w){
        if(h == 0 && w == 0) break;
        ans = 0;
        makemap(h);
        seach();
        cout <<ans <<endl;
    }
    return 0;
}

void makemap(int h){
    for(int i = 0; i < h; i++){
        cin >>str[i];
    }
}

void seach(){
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(str[i][j] == '#' || str[i][j] == '@' || str[i][j] == '*'){
                ans++;
                setblank(j, i, str[i][j]);
            }
        }
    }
}

void setblank(int x, int y, char c){
    int movex[] = {0, 1, 0, -1}, movey[] = {-1, 0, 1, 0};
    for(int i = 0; i < 4; i++){
        int nowx = x + movex[i], nowy = y + movey[i];
        if(nowx > w || nowx < 0 || nowy > h || nowy < 0 || str[nowy][nowx] != c) ;
        else{
            str[nowy][nowx] = '!';
            setblank(nowx, nowy, c);
        }
    }
}