#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int h, w;
string s[102];
const int dx[4] = {-1,1,0,0}, dy[4] = {0,0,-1,1};

void rec(int x, int y, char c) {
  if (s[y][x] != c) return;
  s[y][x] = ' ';
  rep (i,4) {
    int tx = x + dx[i], ty = y + dy[i];
    if (tx < 0 || ty < 0 || tx >= w || ty >= h) continue;
    if (s[ty][tx] == c) rec(tx, ty, c);
  }
}

int main() {
  while (cin >> h >> w, h) {
    rep (i,h) cin >> s[i];
    int ans = 0;
    rep (i,h) rep (j,w) if (s[i][j] != ' ') {
      rec(j, i, s[i][j]);
      ans++;
    }
    cout << ans << endl;
  }
  return 0;
}