#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<set>
#include<cstdlib>
#include<cstring>

using namespace std;

#define N 111
int n,m;
char  map[N][N];
bool vist[N][N];
int ans;
int a[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

bool in(int x,int y)
{
    if (x>=0&&x<n&&y>=0&&y<m)
        return true;
    return false;
}

void dfs(int x,int y)
{
    map[x][y]='*';
    int i,j,k;
    for (k=0;k<8;k++)
    {
        i=a[k][0]+x;
        j=a[k][1]+y;
        if ( in(i,j) && map[i][j]=='@')
            dfs(i,j);
    }

}

int main()
{
    freopen("in.txt","r",stdin);

    int i,j,k;

    while (scanf("%d%d",&n,&m)&&(n+m))
    {
        for (i=0;i<n;i++)
            scanf("%s",map+i);

        //memset(vist,false,sizeof(vist));
    
        ans=0;
        for (i=0;i<n;i++)
        {
            for (j=0;j<m;j++)
            {
                if (map[i][j]=='@')
                {
                    //cout<<i<<' '<<j<<endl;
                    ans++;
                    dfs(i,j);
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}






B - Oil Deposits


Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%lld & %llu


Submit Status


Description





Input



The input file contains one or more grids. Each grid begins with a line containing m and n, the number of rows and columns in the grid, separated by a single space. If m = 0 it signals the end of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100. Following this are m lines of n characters each (not counting the end-of-line characters). Each character corresponds to one plot, and is either `*', representing the absence of oil, or `@', representing an oil pocket.



Output



For each grid, output the number of distinct oil deposits. Two different pockets are part of the same oil deposit if they are adjacent horizontally, vertically, or diagonally. An oil deposit will not contain more than 100 pockets.


Sample Input



1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0



Sample Output

0


1


2


2