
char yeild[102][102];

int h,w;
int res = 0;
#include<cstdio>
void dfs(int i, int j, char c){
    yeild[i][j] = '.';
    for(int x = -1; x <= 1; x++){
        for(int y = -1; y <= 1; y++){
            if((x == -1 || x == 1) && y != 0) continue;
            int dx = i + x, dy = j + y;

            if(c == '#' && 0 <= dx && dx < h && 0 <= dy && dy < w && yeild[dx][dy] == '#')
                dfs(dx,dy,c);
            if(c == '@' && 0 <= dx && dx < h && 0 <= dy && dy < w && yeild[dx][dy] == '@')
                dfs(dx,dy,c);
            if(c == '*' && 0 <= dx && dx < h && 0 <= dy && dy < w && yeild[dx][dy] == '*')
                dfs(dx,dy,c);

        }
    }

}

int main(){
	//?入果?
//	while(scanf("%d%d",&h,&w) && h != 0 && w != 0){
    while(scanf("%d%d",&h,&w) && ( h || w)){
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				scanf(" %c",&yeild[i][j]);
			}
		}
    for(int i = 0; i < h; i++){
        for(int j = 0 ; j < w; j++){
            if(yeild[i][j] == '#'){
                    dfs(i,j,'#');
                    res++;
            }
            if(yeild[i][j] == '@'){
                    dfs(i,j,'@');
                    res++;
            }
            if(yeild[i][j] == '*'){
                    dfs (i,j,'*');
                    res++;
            }
        }
    }
    printf("%d\n",res);
	}

	return 0;
}