#include<iostream>
#include<string>
#include<vector>

using namespace std;

void Search1(vector<string>&, int, int, int, int, char);
void Search2(vector<string>&, int, int, int, int, char);

int main(){
  int i, j, h, w, count;
  char c;
  string s;
  vector<string> data;

  while(1){
    cin >> h >> w;
    if(h == 0 && w == 0) break;

    for(i=0; i<h; ++i){
      cin >> s;
      data.push_back(s);
    }

    for(i=0, count = 0; i<h; ++i){
      for(j=0; j<w; ++j){
	if(data[i][j] != '1'){
	  c = data[i][j];
	  Search1(data, i, j, h, w, c);
	  ++count;
	}
      }
    }

    cout << count << endl;
    data.clear();
  }

  return 0;
}

void Search1(vector<string>& data, int i, int j, int h, int w, char c){
  data[i][j] = '1';
  Search2(data, i-1, j, h, w, c);
  Search2(data, i+1, j, h, w, c);
  Search2(data, i, j-1, h, w, c);
  Search2(data, i, j+1, h, w, c);
}

void Search2(vector<string>& data, int i, int j, int h, int w, char c){
  if(i > -1 && i < h && j > -1 && j < w && data[i][j] == c)
    Search1(data, i, j, h, w, c);
}