#include <iostream>
#include <cstring>
using namespace std;

string field[501];
int H,W;

void harvest(int i,int j,string fruit) {
  field[i].replace(j,1,"x");
  if(j < W-1) {
    if(field[i].substr(j+1,1) == fruit) {
      harvest(i,j+1,fruit);
    }
  }
  if(i < H-1) {
    if(field[i+1].substr(j,1) == fruit) {
      harvest(i+1,j,fruit);
    }
  }
  if(j >= 1) {
    if(field[i].substr(j-1,1) == fruit) {
      harvest(i,j-1,fruit);
    }
  }
  if(i >= 1) {
    if(field[i-1].substr(j,1) == fruit) {
      harvest(i-1,j,fruit);
    }
  }
}

int main() {
  int member=0;
  string str,fruit;
  while(cin >> H >> W) {
    getline(cin,str);// kill \n
    if((H == 0) && (W == 0)) break;
    for(int i=0;i<H;i++) { //get field for string
      getline(cin,str);
      field[i] = str;
    }

    for(int i=0;i<H;i++) {
      for(int j=0;j<W;j++) {

        if((field[i].substr(j,1) == "#") || (field[i].substr(j,1) == "@")||(field[i].substr(j,1) == "*")) {
          fruit = field[i].substr(j,1);
          harvest(i,j,fruit);
          member++;
        }
      }
    }
    cout << member << endl; // for test
    member = 0;
  }

}