#include <iostream>
#include <sstream>
#include <cstdlib>

const int MAX_W = 100;
const int MAX_H = 100;
char field[MAX_H][MAX_W] = {'.'};

void solve(int y, int x, int h, int w) {
    int dx[4] = {-1, 0, 1, 0};
    int dy[4] = {0, 1, 0, -1};
    char c = field[y][x];
    field[y][x] = '.';

    for(int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(nx >= 0 and ny >= 0 and nx < w and ny < h and field[ny][nx] == c) {
            solve(ny, nx, h, w);
        }
    }


}

void print(int w, int h) {
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            std::cout << field[i][j];
        }
        std::cout << std::endl;
    }

    std::cout << std::endl;
}

int main() {
    std::string line;
    int w = 0;
    int h = 0;
    std::getline(std::cin, line);
    std::stringstream ss(line);
    std::string buf;
    std::getline(ss, buf, ' ');
    h = atoi(buf.c_str());
    std::getline(ss, buf, ' ');
    w = atoi(buf.c_str());
    int i = 0;
    while(getline(std::cin, line)) {
        if(line == "0 0") {
            break;
        }

        for(int j = 0; j < line.length(); j++) {
            field[i][j] = line[j];
        }

        i++;
    }

    int result = 0;
    for(i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(field[i][j] != '.') {
               // print(w, h);
                solve(i, j, h, w);
                result++;
            }
        }
    }

    std::cout << result << std::endl;
    return 0;
}