#include <iostream>
#include <string>
#include <queue>

using namespace std;

int w, h;
string f[102];
int counts;
int dx[] = {-1, 1,  0, 0};
int dy[] = { 0, 0, -1, 1};

inline void mapp(int x, int y, char z) {

  for (int i=0; i<4; i++) {
  	f[y][x] = '$';
    int newx = x + dx[i];
    int newy = y + dy[i];

    if (newx < 0 || w <= newx || newy < 0 || h <= newy || f[newy][newx] != z) { 
    	continue; 
    }
    mapp(newx, newy,z);
  }
}

int main() {
  while(cin >> w >> h,w||h){
    for (int i=0; i<h; i++) {
      cin >> f[i];
    }
    counts = 0;

    for (int y=0; y<h; y++) {
      for (int x=0; x<w; x++) {
        if(f[y][x] == '*'){
        	counts++;
        	mapp(x,y,'*');
        }
		else if(f[y][x] == '@'){	
		    counts++;
        	mapp(x,y,'@');
        }
        else if(f[y][x] == '#'){
        	counts++;
        	mapp(x,y,'#');
        } 
        
      }
    }
    /*for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			cout << f[y][x];
		}
	}*/
    cout << counts <<endl;
  }
  return 0;
}