#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define inf (1e9)
#define eps (1e-9)

template<class S, class T> inline
ostream& operator<<(ostream&os, pair<S,T> p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template<class S, class T, class U> inline
ostream& operator<<(ostream&os, tuple<S,T,U> t) {
  return os << '('
    << get<0>(t) << ", "
    << get<1>(t) << ", "
    << get<2>(t) << ')';
}

template<class T> inline
ostream& operator<<(ostream&os, vector<T> v) {
  if (v.size() == 0) { return os << "(empty)"; }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

template<class T> inline
istream& operator>>(istream&is, vector<T>&v) {
  rep (i, v.size()) is >> v[i];
  return is;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

typedef vector<int> vi;
typedef vector<vi> vvi;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout.setf(ios::fixed);
  cout.precision(10);
  random_device dev;
  mt19937 rand(dev());

  loop {

  int h, w; cin >> h >> w;
  if (not h and not w) break;

  vvi f(h, vi(w, 0));
  rep (i, h) {
    rep (j, w) {
      char c; cin >> c;
      f[i][j] =
        c == '#' ? 1
        : c == '@' ? 2 : 3;
    }
  }

  int ans = 0;
  rep (i, h) {
    rep (j, w) {
      if (f[i][j] == 0) continue;
      ++ans;
      int finding = f[i][j];
      stack<pair<int,int>> s;
      s.push({ i, j });
      while (not s.empty()) {
        auto p = s.top(); s.pop();
        int u = p.first;
        int v = p.second;
        if (u < 0 or u >= h or v < 0 or v >= w) continue;
        if (f[u][v] != finding) continue;
        f[u][v] = 0;
        rep (k, 4) s.push({ u + dx[k], v + dy[k] });
      }
    }
  }

  cout << ans << endl;

  }

  return 0;
}