#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back

main(){
  int w,h;
  while(cin>>h>>w){
    if(h==0 && w==0)break;
    string kukaku[h];
    rep(i,h)cin>>kukaku[i];

    int wake[h][w];
    memset(wake,0,sizeof(wake));
    int ans=0;
    rep(i,h){
      rep(j,w){
        if(wake[i][j])continue;
        ++ans;
        queue<PI> Q;
        Q.push(mp(i,j));
        wake[i][j]=ans;
        while(!Q.empty()){
          int x=Q.front().first,y=Q.front().second;
          Q.pop();
          int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
          rep(k,4){
            int nx=x+dx[k],ny=y+dy[k];
            if(nx<0 || nx>=h || ny<0 || ny>=w || wake[nx][ny] || kukaku[nx][ny]!=kukaku[x][y])continue;
            Q.push(mp(nx,ny));
            wake[nx][ny]=ans;
          }
        }
      }
    }
    cout<<ans<<endl;
  }
}