//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>

#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)


typedef long long ll;

int mx[]={-1,1,0,0};
int my[]={0,0,-1,1};
using namespace std;
void dfs(int x,int y,vector<vector<int> > &map,int f){
    if(x<0 or y<0 or x>map.size()-1 or y>map[0].size()-1 or map[x][y]!=f) return;
    map[x][y]=0;
    for(int i=0;i<4;i++)dfs(x+mx[i],y+my[i],map,f);
    
}
int main(){
    int x,y;
    while(cin>>x>>y,x|y){
        vector<vector<int> > map;

        
        for(int i=0;i<x;i++){
            vector<int> tmp;
            string s;
            cin>>s;
            for(int j=0;j<y;j++){

                if(s[j]=='#') {tmp.push_back(1);}
                else if(s[j]=='@') tmp.push_back(2);
                else tmp.push_back(3);    
            }
            map.push_back((tmp));
        }
        int n=0;
        for(int i=0;i<x;i++){
            for(int j=0;j<y;j++){
                //cout<<i<<j<<endl;
                if(map[i][j]!=0) dfs(i,j,map,map[i][j]),n++;
            }
        }
        cout<<n<<endl;
        
    }
    return 0;
};