#include <iostream>
#include <string.h>
using namespace std;
void dfs(char ch[105][105],int i,int j,bool visit[105][105],int m,int n)
{
    visit[i][j]= true;
    if(i-1>=0&&!visit[i-1][j]&&ch[i-1][j]=='#')
        dfs(ch,i-1,j,visit,m,n);
    if(i+1<m&&!visit[i+1][j]&&ch[i+1][j]=='#')
        dfs(ch,i+1,j,visit,m,n);
    if(j-1>=0&&!visit[i][j-1]&&ch[i][j-1]=='#')
        dfs(ch,i,j-1,visit,m,n);
    if(j+1<n&&!visit[i][j+1]&&ch[i][j+1]=='#')
        dfs(ch,i,j+1,visit,m,n);
}
void dfs1(char ch[105][105],int i,int j,bool visit[105][105],int m,int n)
{
    visit[i][j]= true;
    if(i-1>=0&&!visit[i-1][j]&&ch[i-1][j]=='@')
        dfs1(ch,i-1,j,visit,m,n);
    if(i+1<m&&!visit[i+1][j]&&ch[i+1][j]=='@')
        dfs1(ch,i+1,j,visit,m,n);
    if(j-1>=0&&!visit[i][j-1]&&ch[i][j-1]=='@')
        dfs1(ch,i,j-1,visit,m,n);
    if(j+1<n&&!visit[i][j+1]&&ch[i][j+1]=='@')
        dfs1(ch,i,j+1,visit,m,n);
}
void dfs2(char ch[105][105],int i,int j,bool visit[105][105],int m,int n)
{
    visit[i][j]= true;
    if(i-1>=0&&!visit[i-1][j]&&ch[i-1][j]=='*')
        dfs2(ch,i-1,j,visit,m,n);
    if(i+1<m&&!visit[i+1][j]&&ch[i+1][j]=='*')
        dfs2(ch,i+1,j,visit,m,n);
    if(j-1>=0&&!visit[i][j-1]&&ch[i][j-1]=='*')
        dfs2(ch,i,j-1,visit,m,n);
    if(j+1<n&&!visit[i][j+1]&&ch[i][j+1]=='*')
        dfs2(ch,i,j+1,visit,m,n);
}
int main() {
    int n,m;
    cin>>m>>n;
    while (n!=0 &&m!=0) {
        int result = 0;
        bool visit[105][105];
        memset(visit, false, sizeof(visit));
        char ch[105][105];
        int i, j;
        for (i = 0; i < m; i++)
            for (j = 0; j < n; j++)
                cin >> ch[i][j];
        for (i = 0; i < m; i++)
            for (j = 0; j < n; j++) {
                if(!visit[i][j])
                {
                    visit[i][j]=true;
                    if(ch[i][j]=='#')
                    {
                        dfs(ch,i,j,visit,m,n);
                        result++;
                    }
                    if(ch[i][j]=='@')
                    {
                        dfs1(ch,i,j,visit,m,n);
                        result++;
                    }
                    if(ch[i][j]=='*')
                    {
                        dfs2(ch,i,j,visit,m,n);
                        result++;
                    }
                }

            }
        cout << result << endl;
        cin >> m >> n;
    }
    return 0;
}
