//很有意思的一个题目 判断连通则并集
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
struct node{
int x;
int y;
};
node p[52][52];
int deep[52][52];
int dir[4][2] = {{-1,0},{1, 0},{0,-1},{0,1}};
bool hash[52][52];
char map[52][52];
inline void make_set(int n,int m)
{
int i,j;
for(i = 0; i <= n; i++)
for(j = 0; j <= m; j++)
{
p[i][j].x = i;
p[i][j].y = j;
deep[i][j] = 1;
hash[i][j] = true;
}
}
inline node find(node x)
{
node r,i;
r = x;
while(p[r.x][r.y].x != r.x || p[r.x][r.y].y != r.y)
{
i = r;
r = p[r.x][r.y];
p[i.x][i.y] = p[r.x][r.y];
}
return r;
}
inline void merge(node a,node b)
{
node fa = find(a);
node fb = find(b);
if(fa.x != fb.x || fb.y != fa.y)
{
if(deep[fa.x][fa.y] > deep[fb.x][fb.y])
{
p[fb.x][fb.y] = fa;
}
else
{
p[fa.x][fa.y] = fb;
if(deep[fa.x][fa.y] == deep[fb.x][fb.y])
{
deep[fb.x][fb.y]++;
}
}
}
}
bool isralate(char c,int i)
{
if(c == 'A')
{
if(i == 0 || i == 2)
return true;
}
else if(c == 'B')
{
if(i == 0 || i == 3)
return true;
}
else if(c == 'C')
{
if(i == 1 || i == 2)
return true;
}
else if(c == 'D')
{
if(i == 1 || i == 3)
return true;
}
else if(c == 'E')
{
if(i == 0 || i == 1)
return true;
}
else if(c == 'F')
{
if(i == 2 || i == 3)
return true;
}
else if(c == 'G')
{
if(i == 0 || i == 3 || i == 2)
return true;
}
else if(c == 'H')
{
if(i == 0 || i == 1 || i == 2)
return true;
}
else if(c == 'I')
{
if(i == 1 || i == 3 || i == 2)
return true;
}
else if(c == 'J')
{
if(i == 0 || i == 3 || i == 1)
return true;
}
else if(c == 'K')
{
return true;
}
return false;
}
void judge(int n,int m)
{
node N,P;
int i,j,k;
for(k = 0; k < n; k++)
for(j = 0; j < m; j++)
{
N.x = k;
N.y = j;
for(i = 0; i < 4; i++)
{
P.x = N.x + dir[i][0];
P.y = N.y + dir[i][1];
if(P.x >= n || P.y >= m || P.x < 0 || P.y < 0 || hash[P.x][P.y] == false)continue;
if(i == 0)
{
if(isralate(map[P.x][P.y],1) && isralate(map[N.x][N.y],i))
{
merge(N,P);
}
}
else if(i == 1)
{
if(isralate(map[P.x][P.y],0) && isralate(map[N.x][N.y],i))
{
merge(N,P);
}
}
else if(i == 2)
{
if(isralate(map[P.x][P.y],3) && isralate(map[N.x][N.y],i))
{
merge(N,P);
}
}
else if(i == 3)
{
if(isralate(map[P.x][P.y],2) && isralate(map[N.x][N.y],i))
{
merge(N,P);
}
}
hash[N.x][N.y] = false;
}
}
}
int main()
{
int n,m;
int i,j;
int count;
while(scanf("%d%d",&n,&m) != EOF && (n >= 0 && m >= 0))
{
make_set(n,m);
count = 0;
for(i = 0; i < n; i++)
{
scanf("%s",&map[i]);
}
judge(n,m);
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)
{
if(p[i][j].x == i && p[i][j].y == j)
{
count++;
}
}
printf("%d/n",count);
}
}