#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))

typedef long long ll;
typedef complex<double> point;

// up right down left
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

const double EPS = 1e-9;
const int days[]     = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

int main(){
    while(true){
        int h,w;
        cin >> h >> w;
        if(h == 0 and w == 0 ) break;
        vector<vector<int> > number(h+2,vector<int>(w+2,0));
        vector<vector<char> > input(h+2,vector<char>(w+2,'.'));
        for(int i=1;i<=h;i++){
            string s;
            cin >> s;
            for(int j=1;j<=w;j++){
                input[i][j] = s[j-1];
            }
        }
        int now = 1;
        int cnt = 0;
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                if(number[i][j] == 0){
                    char c = input[i][j];
                    // h,w
                    queue<pair<int,int> > Q;
                    Q.push(mp(i,j));
                    number[i][j] = now;
                    while(!Q.empty()){
                        int qh = Q.front().first;
                        int qw = Q.front().second;
                        Q.pop();
                        for(int k=0;k<4;k++){
                            int newh = qh+dy[k];
                            int neww = qw+dx[k];
                            if(number[newh][neww] == 0 and input[newh][neww] == c){
                                number[newh][neww] = now;
                                Q.push(mp(newh,neww));
                            }
                        }
                    }
                    now++;
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}