#include<iostream>
#include<vector>
#include<queue>
using namespace std;

typedef pair<int,int> pii;
#define fi first
#define se second

int main() {
  int h,w;
  char c;
  while(cin>>h>>w, h||w) {
    vector< vector<int> > m(h, vector<int>(w, 0));
    cin.ignore();
    for(int i=0; i<h; ++i) {
      for(int j=0; j<w; ++j) {
	cin>>c;
	if(c=='#')
	  m[i][j] = 0;
	if(c=='*')
	  m[i][j] = 1;
	if(c=='@')
	  m[i][j] = 2;
      }
      cin.ignore();
    }

    int ans = 0;
    int dx[4] = {-1, 1, 0, 0};
    int dy[4] = {0, 0, 1, -1};
    for(int i=0; i<h; ++i) {
      for(int j=0; j<w; ++j) {
	if(m[i][j] != -1) {
	  queue<pii> qu;
	  int now = m[i][j];
	  ans++;
	  for(qu.push(pii(j,i)); !qu.empty();) {
	    pii pos = qu.front(); qu.pop();
	    m[pos.se][pos.fi] = -1;
	    for(int k=0; k<4; ++k)
	      if(pos.fi+dx[k] >= 0 && pos.fi+dx[k] < w 
		 && pos.se+dy[k] >= 0 && pos.se+dy[k] < h && m[pos.se+dy[k]][pos.fi+dx[k]] == now)
		qu.push(pii(pos.fi+dx[k], pos.se+dy[k]));
	  }
	}
      }
    }

    cout<<ans<<endl;
  }
}