#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <bitset>
using namespace std;
  
const double EPS = 1e-9;

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

void Fill(vector<string> &v, int x, int y, char c){
	if(v[y][x] == c){
		v[y][x] = '0';
		for(int i = 0; i < 4; i++){
			Fill(v, x+dx[i], y+dy[i], c);
		}
	}
}

void print_vs(vector<string> v){
	for(int i = 0; i < v.size(); i++){
		for(int j = 0; j < v[i].size(); j++){
			cout << v[i][j];
		}
		cout << endl;
	}
}

int main(){
	int H, W;

	while(cin >> H >> W, H+W){
		vector<string> v(H+2);
		for(int i = 0; i < W+2; i++){
			v[0]+='0';
		}
		v[H+1] = v[0];
		string s;
		for(int i = 1; i <= H; i++){
			cin >> s;
			v[i] = '0'+s+'0';
		}
		int cnt = 0;

		for(int i = 1; i < W+1; i++){
			for(int j = 1; j < H+1; j++){
				if(v[j][i] != '0'){
					cnt++;
					Fill(v, i, j, v[j][i]);	
					//string a;
					//cin >> a;
					//print_vs(v);
				}
			}
		}

		cout << cnt << endl;
	}
  
    return 0;
}