#include<iostream>
#include<string>
using namespace std;
int main() {
	string date[111],dateoki[111];
	int date2[111][111];
	int ps;
	int h,w;
	while (1) {
		cin >> h >> w;
		if (h == 0 && w == 0) {
			goto a;
		}
		ps = 0;
		for (int i = 1; i <= 100; i++) {
			for (int m = 1; m <= 100; m++) {
				date2[i][m] = 0;
			}
		}
		for (int i = 1; i <= h; i++) {
			cin >> date[i];
		}
		for (int i = 1; i <= h; i++) {
			for (int m = 0; m <= w-1; m++) {
				if (i == 1) {
					if (m == 0) {
						ps=ps + 1;
						date2[1][1] = ps;
					}
					if (m != 0) {
						if (date[i][m] == date[i][m - 1]){
							date2[i][m] = date2[i][m - 1];
						}
						else {
							ps = ps + 1;
							date2[i][m] = ps;
						}
					}
				}
				if (i != 1) {
					if (m == 0) {
						if (date[i][m] == date[i - 1][m]) {
							date2[i][m] = date2[i - 1][m];
						}
						else {
							ps = ps + 1;
							date2[i][m] = ps;
						}
					}
					else {
						if (date[i][m] == date[i - 1][m]) {
							date2[i][m] = date2[i - 1][m];
						}
						else {
							ps = ps + 1;
							date2[i][m] = ps;
						}
						if (date[i][m] == date[i][m - 1]) {
							if (date2[i][m] != date2[i][m - 1]) {
								for (int s = 1; s <= h; s++) {
									for (int e = 0; e <= w-1; e++) {
										if (date2[s][e] == date2[i][m]) {
											date2[s][e] = date2[i][m - 1];
										}
									}
								}
							}
						}
					}
				}
			}
		}
		int ans;
		ans = 0;
		int box[111111], bo;
		bo = 0;
		for (int i = 1; i <= h; i++) {
			for (int m = 0; m <= w-1; m++) {
				for (int s = 1; s <= bo; s++) {
					if (date2[i][m] == box[s]) {
						goto b;
					}
				}
				bo = bo + 1;
				box[bo] = date2[i][m];
			b:;
			}
		}
		cout << bo << endl;
	}
a:;
}

