#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<30
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
int h,w;
int cmap[110][110];
bool visited[110][110];
static const int dx[4] = {0,1,0,-1};
static const int dy[4] = {1,0,-1,0};

void dfs(char c,int x,int y){
  visited[y][x] = true;
  for(int i=0;i<4;i++){
    int nx = x+dx[i],ny = y+dy[i];
    if(0<=nx && nx<w && 0<=ny && ny <h && c == cmap[ny][nx] && !visited[ny][nx]){
      dfs(c,nx,ny);
    }
  }

}



int main(){
  while(true){
    int cnt=0;
    cin >> h >> w;
    if(h+w  == 0)break;
    string s;
    for(int i=0;i<h;i++){
      cin >> s;
      for(int j=0;j<s.length();j++){
	cmap[i][j] = s[j];
	visited[i][j] = false;
      }
    }

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(!visited[i][j]){
	  cnt++;
	  dfs(cmap[i][j],j,i);
	}	
      }
    }
    cout << cnt << endl;
  }
return 0;
}