#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#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 <numeric>
#include <list>
#include <iomanip>


using namespace std;
typedef long long ll;
const int MODULO = 1000000007;
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define SZ(c) ((int)(c).size())

int n,m;
bool use[100][100];
char s[100][101];
int dx[] =  {0,0,1,-1};
int dy[] =  {1,-1,0,0};

void dfs(int x,int y){
	use[y][x] = true;
	FOR(i,4){
		int nx = x + dx[i],ny = y + dy[i];
		if(0 <= nx && nx < m && 0 <= ny && ny < n && (!use[ny][nx]) && s[y][x] == s[ny][nx]){
			dfs(nx,ny);
		}
	}
}

int main(){
	while(cin>>n>>m,(n||m)){
		FOR(i,n) cin>>s[i];
		memset(use,0,sizeof(use));
		int ans = 0;
		FOR(i,n)FOR(j,m){
			if(!use[i][j]){
				ans++;
				dfs(j,i);
			}
		}
		cout << ans << endl;
	}
	return 0;
}