#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;


void dfs(vector<string>& matrix, int n, int m, int x, int y, const char t) {
    if(x < 0 || x >= n || y < 0 || y >= m || matrix[x][y] != t) return;
    matrix[x][y] = 'x';
    dfs(matrix, n, m, x-1, y, t);
    dfs(matrix, n, m, x+1, y, t);
    dfs(matrix, n, m, x, y-1, t);
    dfs(matrix, n, m, x, y+1, t);
}

void solve(vector<string>& matrix, int n, int m) {
    int count = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(matrix[i][j] != 'x') {
                dfs(matrix, n, m, i, j, matrix[i][j]);
                count++;
            }
        }
    }

    cout << count << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    while(cin >> n >> m && n != 0 && m != 0) {
        vector<string> matrix(n);
        for(int i = 0; i < n; i++) {
            cin >> matrix[i];
        }
        solve(matrix, n, m);
    }
    return 0;
}
