#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main()
{
	int h, w;
	while(scanf("%d%d", &h, &w), h){
		char field[128][128];
		rep(i, h)
			scanf("%s", field[i]);
		
		int distribution = 0;
		bool visited[128][128] = {false};
		rep(i, h) rep(j, w){
			if(!visited[i][j]){
				++distribution;
				char now = field[i][j];
				
				stack<pii> S;
				S.push(pii(i, j));
				while(!S.empty()){
					pii pos = S.top();
					S.pop();
					if(visited[pos.first][pos.second])
						continue;
					visited[pos.first][pos.second] = true;
					
					const int dy[] = {0, -1, 1, 0};
					const int dx[] = {-1, 0, 0, 1};
					rep(i, 4){
						int py = pos.first + dy[i];
						int px = pos.second + dx[i];
						if(py<0 || h<=py || px<0 || w<=px)
							continue;
						
						if(field[py][px] == now)
							S.push(pii(py, px));
					}
				}
			}
		}
		printf("%d\n", distribution);
	}

	return 0;
}